From mboxrd@z Thu Jan 1 00:00:00 1970 From: KDr2 Subject: Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode Date: Thu, 22 May 2014 20:45:24 +0800 Message-ID: References: <87sipky46c.fsf@gmail.com> <87tx9zk5ln.fsf@gmail.com> <87d2gmiqle.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e0118243ae3847404f9fc7de8 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45853) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WnSNa-0008Cg-Iy for emacs-orgmode@gnu.org; Thu, 22 May 2014 08:45:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WnSNX-0003Xi-MJ for emacs-orgmode@gnu.org; Thu, 22 May 2014 08:45:50 -0400 Received: from mail-ob0-x22b.google.com ([2607:f8b0:4003:c01::22b]:55048) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WnSNW-0003XU-Ue for emacs-orgmode@gnu.org; Thu, 22 May 2014 08:45:47 -0400 Received: by mail-ob0-f171.google.com with SMTP id wn1so3748661obc.2 for ; Thu, 22 May 2014 05:45:46 -0700 (PDT) In-Reply-To: <87d2gmiqle.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Cc: emacs-orgmode@gnu.org --089e0118243ae3847404f9fc7de8 Content-Type: text/plain; charset=UTF-8 Hi, all This patch is finally merged into the master branch, we can export results of scheme code block under batch mode now. Thanks to Eric, Bastien and Oleh. On Sat, Apr 12, 2014 at 10:12 PM, Eric Schulte wrote: > KDr2 writes: > > > HI, Eric > > > > You are right, I remove the usage of advice now, and use the method you > > (nearly) gave, only 1 little change: > > I found the code: > > ---- > > (defun t1 () (message "abc")) > > ;;(symbol-function 't1) > > > > (let ((hold #'t1)) > > (defun t1 () (message "def")) > > (setq t1 hold)) > > ;;(symbol-function 't1) > > ---- > > > > did recover the t1 function after it executed, so I use this way: > > ---- > > (defun t1 () (message "abc")) > > ;;(symbol-function 't1) > > > > (let ((hold (symbol-function 't1))) > > (defun t1 () (message "def")) > > (fset 't1 hold)) > > > > ;;(symbol-function 't1) > > ---- > > > > Using fset is more readable than my proposal. Very nice. > > > > > And the new patch is attached. > > > > Thanks, however unwind-protect is not used correctly. Make sure that > the value of message is reset in the unwindforms portion of > unwind-protect. > > > > > BTW: I received a PDF assignment form from FSF, but the developer name > and > > the target program on it were wrong (It's for another person who > > contributes to GCC, I think), so I reply that mail for a new PDF > assignment > > form, I 'll tell you after these things done. > > > > Great, let Bastien and myself know when this comes through and he'll add > you to the contributors list and I'll apply the patch. > > Best, > > > > > Thanks. > > > > > > On Sat, Apr 12, 2014 at 3:18 AM, Eric Schulte >wrote: > > > >> Hmmm, > >> > >> Not to be overly nitpicky here, but I see two issues. > >> > >> 1. You should use unwind-protect, to ensure that (ad-unadvise #'message) > >> is run even if @body throws an error, and > >> > >> 2. This will remove any advise which the user has placed on #'message. > >> > >> How about something shaped like the following. > >> > >> (defmacro with-weird-message (&rest body) > >> `(let ((hold #'message) > >> current-message) > >> (unwind-protect > >> (progn > >> (defun message (&rest args) > >> (setq current-message (apply #'format args))) > >> ,@body > >> current-message) > >> (setq message hold)))) > >> > >> Best, > >> > >> P.S. I know this is a lot of process for a small patch, but from this > >> point forward once you have the FSF assignment you can much more > >> easily contribute to ob-scheme and org in general > >> > >> KDr2 writes: > >> > >> > Hi, Eric > >> > > >> > I'm sorry for that I used `flet' in the patch, It's a easy way to let > >> > function `current-message' work in batch mode, so I used it even I saw > >> that > >> > emacs says `flet' is obsolete, I'm sorry for that. > >> > > >> > And I made a new patch(attachment) using `defadvice' for `message' to > >> > capture the message in batch mode, after the message being captured, > the > >> > advice function is removed. Is this way OK? > >> > > >> > And I also sent a request email to assign@gnu.org, and now waiting > the > >> > reply. > >> > > >> > Thanks. > >> > > >> > > >> > On Fri, Apr 11, 2014 at 10:45 AM, Eric Schulte < > schulte.eric@gmail.com > >> >wrote: > >> > > >> >> We can no longer use `flet' in the Org-mode code base, please re-work > >> >> this patch w/o flet. > >> >> > >> >> Also, I don't see your name in the list of contributors, and (I > believe) > >> >> this patch is too large to apply w/o FSF assignment. See the > following > >> >> page on how to contribute to Org-mode. > >> >> > >> >> http://orgmode.org/worg/org-contribute.html > >> >> > >> >> KDr2 writes: > >> >> > >> >> > The bug: > >> >> > write file ~/scheme-test.org with the content below: > >> >> > -------8<-------------- > >> >> > #+BEGIN_SRC scheme :exports results :results output raw > >> >> > (display "Hello Scheme in OrgMode") > >> >> > #+END_SRC > >> >> > -------8<-------------- > >> >> > > >> >> > and run: > >> >> > > >> >> > emacs --batch --eval='(load "~/.emacs.d/init.el")' > ~/scheme-test.org-f > >> >> > org-html-export-to-html > >> >> > > >> >> > you will find the bug: > >> >> > > >> >> > `org-babel-scheme-execute-with-geiser' uses `current-message' to > get > >> the > >> >> > results of scheme code blocks, but `current-message' always returns > >> nil > >> >> in > >> >> > batch mode, and this patch fixes this. > >> >> > > >> >> > -- > >> >> > >> >> -- > >> >> Eric Schulte > >> >> https://cs.unm.edu/~eschulte > >> >> PGP: 0x614CA05D > >> >> > >> > > >> > > >> > > >> > -- > >> > -- > >> > > >> > KDr2, http://kdr2.com > >> > > >> > From fe5549f3f48acf9b51aeb3706eb8dd3d76ab18c1 Mon Sep 17 00:00:00 2001 > >> > From: KDr2 > >> > Date: Fri, 11 Apr 2014 12:56:24 +0800 > >> > Subject: [PATCH] lisp/ob-scheme.el: Fix scheme code blocks execution > >> error in > >> > batch mode > >> > > >> > * lisp/ob-scheme.el (org-babel-scheme-capture-current-message, > >> org-babel-scheme-execute-with-geiser): Capture scheme code results via > >> current-message both in interactive mode and noninteractive mode. > >> > > >> > `org-babel-scheme-execute-with-geiser' uses `current-message' to get > the > >> results of scheme code blocks, but `current-message' always returns nil > in > >> batch mode, and this patch fixes this. > >> > > >> > Modified from a patch proposal by KDr2(killy.draw@gmail.com) > >> > --- > >> > lisp/ob-scheme.el | 20 +++++++++++++++++--- > >> > 1 file changed, 17 insertions(+), 3 deletions(-) > >> > > >> > diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el > >> > index b7117e9..6b82c6e 100644 > >> > --- a/lisp/ob-scheme.el > >> > +++ b/lisp/ob-scheme.el > >> > @@ -118,6 +118,19 @@ org-babel-scheme-execute-with-geiser will use a > >> temporary session." > >> > (name)))) > >> > result)) > >> > > >> > +(defmacro org-babel-scheme-capture-current-message (&rest body) > >> > + "Capture current message in both interactive and noninteractive > mode" > >> > + `(if noninteractive > >> > + (let ((current-message nil)) > >> > + (defadvice message (after capture-current-message activate) > >> > + (setq current-message ad-return-value)) > >> > + ,@body > >> > + (ad-unadvise #'message) > >> > + current-message) > >> > + (progn > >> > + ,@body > >> > + (current-message)))) > >> > + > >> > (defun org-babel-scheme-execute-with-geiser (code output impl repl) > >> > "Execute code in specified REPL. If the REPL doesn't exist, create > it > >> > using the given scheme implementation. > >> > @@ -142,10 +155,11 @@ is true; otherwise returns the last value." > >> > (current-buffer))))) > >> > (setq geiser-repl--repl repl-buffer) > >> > (setq geiser-impl--implementation nil) > >> > - (geiser-eval-region (point-min) (point-max)) > >> > + (setq result (org-babel-scheme-capture-current-message > >> > + (geiser-eval-region (point-min) (point-max)))) > >> > (setq result > >> > - (if (equal (substring (current-message) 0 3) "=> ") > >> > - (replace-regexp-in-string "^=> " "" (current-message)) > >> > + (if (and (stringp result) (equal (substring result 0 3) > "=> > >> ")) > >> > + (replace-regexp-in-string "^=> " "" result) > >> > "\"An error occurred.\"")) > >> > (when (not repl) > >> > (save-current-buffer (set-buffer repl-buffer) > >> > >> -- > >> Eric Schulte > >> https://cs.unm.edu/~eschulte > >> PGP: 0x614CA05D > >> > > > > > > > > -- > > -- > > > > KDr2, http://kdr2.com > > > > From f20949e18314977bfa3c2ec1a59fb1e7b3269cbd Mon Sep 17 00:00:00 2001 > > From: KDr2 > > Date: Sat, 12 Apr 2014 15:59:37 +0800 > > Subject: [PATCH] lisp/ob-scheme.el: Fix scheme code blocks execution > error in > > batch mode > > > > * lisp/ob-scheme.el (org-babel-scheme-capture-current-message, > org-babel-scheme-execute-with-geiser): Capture scheme code results via > current-message both in interactive mode and noninteractive mode. > > > > `org-babel-scheme-execute-with-geiser' uses `current-message' to get the > results of scheme code blocks, but `current-message' always returns nil in > batch mode, and this patch fixes this. > > > > Modified from a patch proposal by KDr2(killy.draw@gmail.com) > > --- > > lisp/ob-scheme.el | 21 ++++++++++++++++++--- > > 1 file changed, 18 insertions(+), 3 deletions(-) > > > > diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el > > index b7117e9..cf21311 100644 > > --- a/lisp/ob-scheme.el > > +++ b/lisp/ob-scheme.el > > @@ -118,6 +118,20 @@ org-babel-scheme-execute-with-geiser will use a > temporary session." > > (name)))) > > result)) > > > > +(defmacro org-babel-scheme-capture-current-message (&rest body) > > + "Capture current message in both interactive and noninteractive mode" > > + `(if noninteractive > > + (let ((original-message (symbol-function 'message)) > > + (current-message nil)) > > + (defun message (&rest args) > > + (setq current-message (apply original-message args))) > > + (unwind-protect ,@body) > > + (fset 'message original-message) > > + current-message) > > + (progn > > + ,@body > > + (current-message)))) > > + > > (defun org-babel-scheme-execute-with-geiser (code output impl repl) > > "Execute code in specified REPL. If the REPL doesn't exist, create it > > using the given scheme implementation. > > @@ -142,10 +156,11 @@ is true; otherwise returns the last value." > > (current-buffer))))) > > (setq geiser-repl--repl repl-buffer) > > (setq geiser-impl--implementation nil) > > - (geiser-eval-region (point-min) (point-max)) > > + (setq result (org-babel-scheme-capture-current-message > > + (geiser-eval-region (point-min) (point-max)))) > > (setq result > > - (if (equal (substring (current-message) 0 3) "=> ") > > - (replace-regexp-in-string "^=> " "" (current-message)) > > + (if (and (stringp result) (equal (substring result 0 3) "=> > ")) > > + (replace-regexp-in-string "^=> " "" result) > > "\"An error occurred.\"")) > > (when (not repl) > > (save-current-buffer (set-buffer repl-buffer) > > -- > Eric Schulte > https://cs.unm.edu/~eschulte > PGP: 0x614CA05D > -- -- KDr2, http://kdr2.com --089e0118243ae3847404f9fc7de8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi, all

This patch is finally merged in= to the master branch, we can export results of scheme code block under batc= h mode now.

Thanks to Eric, Bastien and Oleh.


On Sat,= Apr 12, 2014 at 10:12 PM, Eric Schulte <schulte.eric@gmail.com&g= t; wrote:
KDr2 <killy.draw@gmail.com> writes:

> HI, Eric
>
> You are right, I remove the usage of advice now, and use the method yo= u
> (nearly) gave, only 1 little change:
> I found the code:
> ----
> (defun t1 () (message "abc"))
> ;;(symbol-function 't1)
>
> (let ((hold #'t1))
> =C2=A0 (defun t1 () (message "def"))
> =C2=A0 (setq t1 hold))
> ;;(symbol-function 't1)
> ----
>
> did recover the t1 function after it executed, so I use this way:
> ----
> (defun t1 () (message "abc"))
> ;;(symbol-function 't1)
>
> (let ((hold (symbol-function 't1)))
> =C2=A0 (defun t1 () (message "def"))
> =C2=A0 (fset 't1 hold))
>
> ;;(symbol-function 't1)
> ----
>

Using fset is more readable than my proposal. =C2=A0Very nice.

>
> And the new patch is attached.
>

Thanks, however unwind-protect is not used correctly. =C2=A0Make sure= that
the value of message is reset in the unwindforms portion of
unwind-protect.

>
> BTW: I received a PDF assignment form from FSF, but the developer name= and
> the target program on it were wrong (It's for another person who > contributes to GCC, I think), so I reply that mail for a new PDF assig= nment
> form, I 'll tell you after these things done.
>

Great, let Bastien and myself know when this comes through and he'= ;ll add
you to the contributors list and I'll apply the patch.

Best,

>
> Thanks.
>
>
> On Sat, Apr 12, 2014 at 3:18 AM, Eric Schulte <schulte.eric@gmail.com>wrote:
>
>> Hmmm,
>>
>> Not to be overly nitpicky here, but I see two issues.
>>
>> 1. You should use unwind-protect, to ensure that (ad-unadvise #= 9;message)
>> =C2=A0 =C2=A0is run even if @body throws an error, and
>>
>> 2. This will remove any advise which the user has placed on #'= message.
>>
>> How about something shaped like the following.
>>
>> =C2=A0 =C2=A0 (defmacro with-weird-message (&rest body)
>> =C2=A0 =C2=A0 =C2=A0 `(let ((hold #'message)
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0current-message) >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(unwind-protect
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(progn
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(defun mess= age (&rest args)
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(set= q current-message (apply #'format args)))
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0,@body
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0current-mes= sage)
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(setq message hold)))) >>
>> Best,
>>
>> P.S. I know this is a lot of process for a small patch, but from t= his
>> =C2=A0 =C2=A0 =C2=A0point forward once you have the FSF assignment= you can much more
>> =C2=A0 =C2=A0 =C2=A0easily contribute to ob-scheme and org in gene= ral
>>
>> KDr2 <killy.draw@gmail.= com> writes:
>>
>> > Hi, Eric
>> >
>> > I'm sorry for that I used `flet' in the patch, It'= ;s a easy way to let
>> > function `current-message' work in batch mode, so I used = it even I saw
>> that
>> > emacs says `flet' is obsolete, I'm sorry for that. >> >
>> > And I made a new patch(attachment) using `defadvice' for = `message' to
>> > capture the message in batch mode, after the message being ca= ptured, the
>> > advice function is removed. Is this way OK?
>> >
>> > And I also sent a request email to assign@gnu.org, and now waiting the
>> > reply.
>> >
>> > Thanks.
>> >
>> >
>> > On Fri, Apr 11, 2014 at 10:45 AM, Eric Schulte <schulte.eric@gmail.com
>> >wrote:
>> >
>> >> We can no longer use `flet' in the Org-mode code base= , please re-work
>> >> this patch w/o flet.
>> >>
>> >> Also, I don't see your name in the list of contributo= rs, and (I believe)
>> >> this patch is too large to apply w/o FSF assignment. =C2= =A0See the following
>> >> page on how to contribute to Org-mode.
>> >>
>> >> =C2=A0 http://orgmode.org/worg/org-contribute.html
>> >>
>> >> KDr2 <killy.dr= aw@gmail.com> writes:
>> >>
>> >> > The bug:
>> >> > write file ~/scheme-test.org with the content below:
>> >> > -------8<--------------
>> >> > #+BEGIN_SRC scheme :exports results :results output = raw
>> >> > =C2=A0 (display "Hello Scheme in OrgMode")=
>> >> > #+END_SRC
>> >> > -------8<--------------
>> >> >
>> >> > and run:
>> >> >
>> >> > emacs --batch --eval=3D'(load "~/.emacs.d/i= nit.el")' ~/scheme-test.org-f
>> >> > org-html-export-to-html
>> >> >
>> >> > you will find the bug:
>> >> >
>> >> > `org-babel-scheme-execute-with-geiser' uses `cur= rent-message' to get
>> the
>> >> > results of scheme code blocks, but `current-message&= #39; always returns
>> nil
>> >> in
>> >> > batch mode, and this patch fixes this.
>> >> >
>> >> > --
>> >>
>> >> --
>> >> Eric Schulte
>> >> https://cs.unm.edu/~eschulte
>> >> PGP: 0x614CA05D
>> >>
>> >
>> >
>> >
>> > --
>> > --
>> >
>> > KDr2, http://kd= r2.com
>> >
>> > From fe5549f3f48acf9b51aeb3706eb8dd3d76ab18c1 Mon Sep 17 00:0= 0:00 2001
>> > From: KDr2 <killy.= draw@gmail.com>
>> > Date: Fri, 11 Apr 2014 12:56:24 +0800
>> > Subject: [PATCH] lisp/ob-scheme.el: Fix scheme code blocks ex= ecution
>> error in
>> > =C2=A0batch mode
>> >
>> > * lisp/ob-scheme.el (org-babel-scheme-capture-current-message= ,
>> org-babel-scheme-execute-with-geiser): Capture scheme code results= via
>> current-message both in interactive mode and noninteractive mode.<= br> >> >
>> > `org-babel-scheme-execute-with-geiser' uses `current-mess= age' to get the
>> results of scheme code blocks, but `current-message' always re= turns nil in
>> batch mode, and this patch fixes this.
>> >
>> > Modified from a patch proposal by KDr2(killy.draw@gmail.com)
>> > ---
>> > =C2=A0lisp/ob-scheme.el | 20 +++++++++++++++++---
>> > =C2=A01 file changed, 17 insertions(+), 3 deletions(-)
>> >
>> > diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el
>> > index b7117e9..6b82c6e 100644
>> > --- a/lisp/ob-scheme.el
>> > +++ b/lisp/ob-scheme.el
>> > @@ -118,6 +118,19 @@ org-babel-scheme-execute-with-geiser wil= l use a
>> temporary session."
>> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(name))))
>> > =C2=A0 =C2=A0 =C2=A0result))
>> >
>> > +(defmacro org-babel-scheme-capture-current-message (&res= t body)
>> > + =C2=A0"Capture current message in both interactive and= noninteractive mode"
>> > + =C2=A0`(if noninteractive
>> > + =C2=A0 =C2=A0 =C2=A0 (let ((current-message nil))
>> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 (defadvice message (after captu= re-current-message activate)
>> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq current-message ad= -return-value))
>> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 ,@body
>> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 (ad-unadvise #'message)
>> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 current-message)
>> > + =C2=A0 =C2=A0 (progn
>> > + =C2=A0 =C2=A0 =C2=A0 ,@body
>> > + =C2=A0 =C2=A0 =C2=A0 (current-message))))
>> > +
>> > =C2=A0(defun org-babel-scheme-execute-with-geiser (code outpu= t impl repl)
>> > =C2=A0 =C2=A0"Execute code in specified REPL. If the REP= L doesn't exist, create it
>> > =C2=A0using the given scheme implementation.
>> > @@ -142,10 +155,11 @@ is true; otherwise returns the last val= ue."
>> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(current-buffer)))))
>> > =C2=A0 =C2=A0 =C2=A0 (setq geiser-repl--repl repl-buffer)
>> > =C2=A0 =C2=A0 =C2=A0 (setq geiser-impl--implementation nil) >> > - =C2=A0 =C2=A0 (geiser-eval-region (point-min) (point-max))<= br> >> > + =C2=A0 =C2=A0 (setq result (org-babel-scheme-capture-curren= t-message
>> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (geiser-eval-region (point-min) (point-max))))
>> > =C2=A0 =C2=A0 =C2=A0 (setq result
>> > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (equal (substring (c= urrent-message) 0 3) "=3D> ")
>> > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (replace-r= egexp-in-string "^=3D> " "" (current-message))
>> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (and (stringp result= ) (equal (substring result 0 3) "=3D>
>> "))
>> > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (replace-r= egexp-in-string "^=3D> " "" result)
>> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\"= ;An error occurred.\""))
>> > =C2=A0 =C2=A0 =C2=A0 (when (not repl)
>> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 (save-current-buffer (set-buffer = repl-buffer)
>>
>> --
>> Eric Schulte
>> https:/= /cs.unm.edu/~eschulte
>> PGP: 0x614CA05D
>>
>
>
>
> --
> --
>
> KDr2, http://kdr2.com
>
> From f20949e18314977bfa3c2ec1a59fb1e7b3269cbd Mon Sep 17 0= 0:00:00 2001
> From: KDr2 <
killy.draw@gmai= l.com>
> Date: Sat, 12 Apr 2014 15:59:37 +0800
> Subject: [PATCH] lisp/ob-scheme.el: Fix scheme code bl= ocks execution error in
> =C2=A0batch mode
>
> * lisp/ob-scheme.el (org-babel-scheme-capture-current-message, org-bab= el-scheme-execute-with-geiser): Capture scheme code results via current-mes= sage both in interactive mode and noninteractive mode.
>
> `org-babel-scheme-execute-with-geiser' uses `current-message' = to get the results of scheme code blocks, but `current-message' always = returns nil in batch mode, and this patch fixes this.
>
> Modified from a patch proposal by KDr2(killy.draw@gmail.com)
> ---
> =C2=A0lisp/ob-scheme.el | 21 ++++++++++++++++++---
> =C2=A01 file changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el
> index b7117e9..cf21311 100644
> --- a/lisp/ob-scheme.el
> +++ b/lisp/ob-scheme.el
> @@ -118,6 +118,20 @@ org-babel-scheme-execute-with-geiser will use a t= emporary session."
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(name)= )))
> =C2=A0 =C2=A0 =C2=A0result))
>
> +(defmacro org-babel-scheme-capture-current-message (&rest body) > + =C2=A0"Capture current message in both interactive and noninter= active mode"
> + =C2=A0`(if noninteractive
> + =C2=A0 =C2=A0 =C2=A0 (let ((original-message (symbol-function = 'message))
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (current-message nil))
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 (defun message (&rest args)
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq current-message (apply orig= inal-message args)))
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 (unwind-protect ,@body)
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 (fset 'message original-message)
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 current-message)
> + =C2=A0 =C2=A0 (progn
> + =C2=A0 =C2=A0 =C2=A0 ,@body
> + =C2=A0 =C2=A0 =C2=A0 (current-message))))
> +
> =C2=A0(defun org-babel-scheme-execute-with-geiser (code output impl re= pl)
> =C2=A0 =C2=A0"Execute code in specified REPL. If the REPL doesn&#= 39;t exist, create it
> =C2=A0using the given scheme implementation.
> @@ -142,10 +156,11 @@ is true; otherwise returns the last value.= "
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(curre= nt-buffer)))))
> =C2=A0 =C2=A0 =C2=A0 (setq geiser-repl--repl repl-buffer)
> =C2=A0 =C2=A0 =C2=A0 (setq geiser-impl--implementation nil)
> - =C2=A0 =C2=A0 (geiser-eval-region (point-min) (point-max))
> + =C2=A0 =C2=A0 (setq result (org-babel-scheme-capture-current-message=
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (geis= er-eval-region (point-min) (point-max))))
> =C2=A0 =C2=A0 =C2=A0 (setq result
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (equal (substring (current-me= ssage) 0 3) "=3D> ")
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (replace-regexp-in-= string "^=3D> " "" (current-message))
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (and (stringp result) (equal = (substring result 0 3) "=3D> "))
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (replace-regexp-in-= string "^=3D> " "" result)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "\"An error= occurred.\""))
> =C2=A0 =C2=A0 =C2=A0 (when (not repl)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 (save-current-buffer (set-buffer repl-buff= er)

--
Eric Schulte
https://cs.unm.e= du/~eschulte
PGP: 0x614CA05D



--
=
--089e0118243ae3847404f9fc7de8--