emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
@ 2014-04-02  3:48 KDr2
  2014-04-08 13:56 ` KDr2
  2014-04-11  2:45 ` Eric Schulte
  0 siblings, 2 replies; 16+ messages in thread
From: KDr2 @ 2014-04-02  3:48 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 565 bytes --]

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.

-- 
-- 

KDr2, http://kdr2.com

[-- Attachment #1.2: Type: text/html, Size: 1075 bytes --]

[-- Attachment #2: 0001-ob-scheme.el-Fix-scheme-code-blocks-execution-error-.patch --]
[-- Type: text/x-patch, Size: 2291 bytes --]

From cebf9fc4fe09ab22fd31ff8e5606d0f680c121e9 Mon Sep 17 00:00:00 2001
From: KDr2 <killy.draw@gmail.com>
Date: Wed, 2 Apr 2014 10:30:38 +0800
Subject: [PATCH] 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
---
 lisp/ob-scheme.el | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el
index b7117e9..3b7ceb2 100644
--- a/lisp/ob-scheme.el
+++ b/lisp/ob-scheme.el
@@ -118,6 +118,17 @@ 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))
+         (flet ((message (fmt &rest args) (setq current-message (apply #'format fmt args))))
+           ,@body
+           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 +153,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)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-02  3:48 [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode KDr2
@ 2014-04-08 13:56 ` KDr2
  2014-04-10  8:27   ` Oleh
  2014-04-11  2:45 ` Eric Schulte
  1 sibling, 1 reply; 16+ messages in thread
From: KDr2 @ 2014-04-08 13:56 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 803 bytes --]

Hi, folks

Has anyone reviewed this patch? Or is there a better way to fix the bug?

Thanks.


On Wed, Apr 2, 2014 at 11:48 AM, KDr2 <killy.draw@gmail.com> wrote:

> 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.
>
> --
> --
>
> KDr2, http://kdr2.com
>



-- 
-- 

KDr2, http://kdr2.com

[-- Attachment #2: Type: text/html, Size: 1960 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-08 13:56 ` KDr2
@ 2014-04-10  8:27   ` Oleh
  2014-04-10  8:36     ` KDr2
  0 siblings, 1 reply; 16+ messages in thread
From: Oleh @ 2014-04-10  8:27 UTC (permalink / raw)
  To: KDr2; +Cc: emacs-orgmode

Hi,

I tried to have a look at your patch, but ob-scheme has stopped working
for me. Can you send me the minimal init.el to make your scheme-test.org
work in interactive mode?

regards,
Oleh

On Tue, Apr 8, 2014 at 3:56 PM, KDr2 <killy.draw@gmail.com> wrote:
> Hi, folks
>
> Has anyone reviewed this patch? Or is there a better way to fix the bug?
>
> Thanks.
>
>
> On Wed, Apr 2, 2014 at 11:48 AM, KDr2 <killy.draw@gmail.com> wrote:
>>
>> 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.
>>
>> --
>> --
>>
>> KDr2, http://kdr2.com
>
>
>
>
> --
> --
>
> KDr2, http://kdr2.com

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-10  8:27   ` Oleh
@ 2014-04-10  8:36     ` KDr2
  2014-04-10  8:55       ` Oleh
  0 siblings, 1 reply; 16+ messages in thread
From: KDr2 @ 2014-04-10  8:36 UTC (permalink / raw)
  To: Oleh; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1725 bytes --]

Hi, Oleh

Thanks for you reply. Here is my config steps:
0. I use Debian(sid) and Emacs 24
1. install guile (using apt): http://www.gnu.org/software/guile/
2. install geiser(http://www.nongnu.org/geiser/) with elpa
    and setting for geiser:

    (setq geiser-active-implementations '(guile))
    (setq geiser-default-implementation 'guile)

 That's all, there's no special settings for orgmode.

Thanks again.



On Thu, Apr 10, 2014 at 4:27 PM, Oleh <ohwoeowho@gmail.com> wrote:

> Hi,
>
> I tried to have a look at your patch, but ob-scheme has stopped working
> for me. Can you send me the minimal init.el to make your scheme-test.org
> work in interactive mode?
>
> regards,
> Oleh
>
> On Tue, Apr 8, 2014 at 3:56 PM, KDr2 <killy.draw@gmail.com> wrote:
> > Hi, folks
> >
> > Has anyone reviewed this patch? Or is there a better way to fix the bug?
> >
> > Thanks.
> >
> >
> > On Wed, Apr 2, 2014 at 11:48 AM, KDr2 <killy.draw@gmail.com> wrote:
> >>
> >> 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.
> >>
> >> --
> >> --
> >>
> >> KDr2, http://kdr2.com
> >
> >
> >
> >
> > --
> > --
> >
> > KDr2, http://kdr2.com
>



-- 
-- 

KDr2, http://kdr2.com

[-- Attachment #2: Type: text/html, Size: 3271 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-10  8:36     ` KDr2
@ 2014-04-10  8:55       ` Oleh
  2014-04-10  9:02         ` KDr2
  0 siblings, 1 reply; 16+ messages in thread
From: Oleh @ 2014-04-10  8:55 UTC (permalink / raw)
  To: KDr2; +Cc: emacs-orgmode

> 0. I use Debian(sid) and Emacs 24
> 1. install guile (using apt): http://www.gnu.org/software/guile/
> 2. install geiser(http://www.nongnu.org/geiser/) with elpa
>     and setting for geiser:
>
>     (setq geiser-active-implementations '(guile))
>     (setq geiser-default-implementation 'guile)
>

I've got emacs trunk, GNU Guile 2.0.9, geiser from MELPA and I'm
getting the results in a *Geiser dbg* window instead of org-mode when
I eval.  So the issue is either with ob-scheme or with my geiser,
which is the development version, but I don't see why it shouldn't
work.

regards,
Oleh

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-10  8:55       ` Oleh
@ 2014-04-10  9:02         ` KDr2
  2014-04-10 10:54           ` Oleh
  0 siblings, 1 reply; 16+ messages in thread
From: KDr2 @ 2014-04-10  9:02 UTC (permalink / raw)
  To: Oleh; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1158 bytes --]

Does your "M-x run-geiser" work? It will lead you to a scheme REPL like
this:

GNU Guile 2.0.9-deb+1-1
Copyright (C) 1995-2013 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> 1
$2 = 1
scheme@(guile-user)>




On Thu, Apr 10, 2014 at 4:55 PM, Oleh <ohwoeowho@gmail.com> wrote:

> > 0. I use Debian(sid) and Emacs 24
> > 1. install guile (using apt): http://www.gnu.org/software/guile/
> > 2. install geiser(http://www.nongnu.org/geiser/) with elpa
> >     and setting for geiser:
> >
> >     (setq geiser-active-implementations '(guile))
> >     (setq geiser-default-implementation 'guile)
> >
>
> I've got emacs trunk, GNU Guile 2.0.9, geiser from MELPA and I'm
> getting the results in a *Geiser dbg* window instead of org-mode when
> I eval.  So the issue is either with ob-scheme or with my geiser,
> which is the development version, but I don't see why it shouldn't
> work.
>
> regards,
> Oleh
>



-- 
-- 

KDr2, http://kdr2.com

[-- Attachment #2: Type: text/html, Size: 2096 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-10  9:02         ` KDr2
@ 2014-04-10 10:54           ` Oleh
  2014-04-10 11:00             ` KDr2
  0 siblings, 1 reply; 16+ messages in thread
From: Oleh @ 2014-04-10 10:54 UTC (permalink / raw)
  To: KDr2; +Cc: emacs-orgmode

Of course it works, that's the first thing I tried.
The issue probably is that the implementation of geiser functions that
ob-scheme uses has been changed.

Oleh

On Thu, Apr 10, 2014 at 11:02 AM, KDr2 <killy.draw@gmail.com> wrote:
> Does your "M-x run-geiser" work? It will lead you to a scheme REPL like
> this:
>
> GNU Guile 2.0.9-deb+1-1
> Copyright (C) 1995-2013 Free Software Foundation, Inc.
>
> Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
> This program is free software, and you are welcome to redistribute it
> under certain conditions; type `,show c' for details.
>
> Enter `,help' for help.
> scheme@(guile-user)> 1
> $2 = 1
> scheme@(guile-user)>
>
>
>
>
> On Thu, Apr 10, 2014 at 4:55 PM, Oleh <ohwoeowho@gmail.com> wrote:
>>
>> > 0. I use Debian(sid) and Emacs 24
>> > 1. install guile (using apt): http://www.gnu.org/software/guile/
>> > 2. install geiser(http://www.nongnu.org/geiser/) with elpa
>> >     and setting for geiser:
>> >
>> >     (setq geiser-active-implementations '(guile))
>> >     (setq geiser-default-implementation 'guile)
>> >
>>
>> I've got emacs trunk, GNU Guile 2.0.9, geiser from MELPA and I'm
>> getting the results in a *Geiser dbg* window instead of org-mode when
>> I eval.  So the issue is either with ob-scheme or with my geiser,
>> which is the development version, but I don't see why it shouldn't
>> work.
>>
>> regards,
>> Oleh
>
>
>
>
> --
> --
>
> KDr2, http://kdr2.com

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-10 10:54           ` Oleh
@ 2014-04-10 11:00             ` KDr2
  2014-04-10 11:22               ` Oleh
  0 siblings, 1 reply; 16+ messages in thread
From: KDr2 @ 2014-04-10 11:00 UTC (permalink / raw)
  To: Oleh; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1777 bytes --]

Version of  geiser I installed: geiser-20140326.951, If it has been
changed, it must be changed in the past 2 weeks ...



On Thu, Apr 10, 2014 at 6:54 PM, Oleh <ohwoeowho@gmail.com> wrote:

> Of course it works, that's the first thing I tried.
> The issue probably is that the implementation of geiser functions that
> ob-scheme uses has been changed.
>
> Oleh
>
> On Thu, Apr 10, 2014 at 11:02 AM, KDr2 <killy.draw@gmail.com> wrote:
> > Does your "M-x run-geiser" work? It will lead you to a scheme REPL like
> > this:
> >
> > GNU Guile 2.0.9-deb+1-1
> > Copyright (C) 1995-2013 Free Software Foundation, Inc.
> >
> > Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
> > This program is free software, and you are welcome to redistribute it
> > under certain conditions; type `,show c' for details.
> >
> > Enter `,help' for help.
> > scheme@(guile-user)> 1
> > $2 = 1
> > scheme@(guile-user)>
> >
> >
> >
> >
> > On Thu, Apr 10, 2014 at 4:55 PM, Oleh <ohwoeowho@gmail.com> wrote:
> >>
> >> > 0. I use Debian(sid) and Emacs 24
> >> > 1. install guile (using apt): http://www.gnu.org/software/guile/
> >> > 2. install geiser(http://www.nongnu.org/geiser/) with elpa
> >> >     and setting for geiser:
> >> >
> >> >     (setq geiser-active-implementations '(guile))
> >> >     (setq geiser-default-implementation 'guile)
> >> >
> >>
> >> I've got emacs trunk, GNU Guile 2.0.9, geiser from MELPA and I'm
> >> getting the results in a *Geiser dbg* window instead of org-mode when
> >> I eval.  So the issue is either with ob-scheme or with my geiser,
> >> which is the development version, but I don't see why it shouldn't
> >> work.
> >>
> >> regards,
> >> Oleh
> >
> >
> >
> >
> > --
> > --
> >
> > KDr2, http://kdr2.com
>



-- 
-- 

KDr2, http://kdr2.com

[-- Attachment #2: Type: text/html, Size: 3073 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-10 11:00             ` KDr2
@ 2014-04-10 11:22               ` Oleh
  2014-04-10 11:32                 ` KDr2
  0 siblings, 1 reply; 16+ messages in thread
From: Oleh @ 2014-04-10 11:22 UTC (permalink / raw)
  To: KDr2; +Cc: emacs-orgmode

> Version of  geiser I installed: geiser-20140326.951, If it has been changed,
> it must be changed in the past 2 weeks ...
>

That's exactly the version that I have.
Which org-mode are you using?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-10 11:22               ` Oleh
@ 2014-04-10 11:32                 ` KDr2
  0 siblings, 0 replies; 16+ messages in thread
From: KDr2 @ 2014-04-10 11:32 UTC (permalink / raw)
  To: Oleh; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 3569 bytes --]

org-plus-contrib-20140407

And the file lisp/ob-scheme.el is the same as it in the master branch:

And the error message before patched:

Loading /home/kdr2/.emacs.d/init.el (source)...
Loading /home/kdr2/.emacs.d/src/elisp/common.el (source)...
Loading pde-load...
Loading pde-loaddefs...
../.emacs.d/src/elisp/tools/init-ace-jump.el: `flet' is an obsolete macro
(as of 24.3); use either `cl-flet' or `cl-letf'.
Loading /home/kdr2/.emacs.d/src/elisp/misc.el (source)...
Loading desktop...
Loading /home/kdr2/.emacs.d/src/elisp/themes/wombat-custom.el (source)...
Loading vline...
Evaluate this scheme code block on your system? (y or n) y
executing Scheme code block...
Starting Geiser REPL for guile ...

Package assoc is obsolete!
Package complete is obsolete!
Guile REPL up and running!
=> "Hello Scheme in OrgMode"
Debugger entered--Lisp error: (wrong-type-argument arrayp nil)
  org-babel-scheme-execute-with-geiser("(display \"Hello Scheme in
OrgMode\")" t guile nil)
  org-babel-execute:scheme("(display \"Hello Scheme in OrgMode\")"
((:comments . "") (:shebang . "") (:cache . "no") (:padline . "") (:noweb .
"no")
(:tangle . "no") (:exports . "results") (:results . "raw output replace")
(:colname-names) (:hlines . "no") (:result-params "replace" "output" "raw")
 (:result-type . output) (:rowname-names) (:session . "none")))
  org-babel-execute-src-block(nil ("scheme" "(display \"Hello Scheme in
OrgMode\")" ((:colname-names) (:rowname-names) (:result-params "replace"
"out
put" "raw" "replace" "output" "raw") (:result-type . output) (:comments .
"") (:shebang . "") (:cache . "no") (:padline . "") (:noweb . "no") (:tangl
e . "no") (:exports . "results") (:results . "replace output raw")
(:session . "none") (:rowname-names) (:result-type . output)
(:result-params "repl
ace" "output" "raw") (:hlines . "no") (:colname-names)) "" nil 0 1))
  org-babel-exp-results(("scheme" "(display \"Hello Scheme in OrgMode\")"
((:cache . "no") (:colname-names) (:comments . "") (:exports . "results") (
:hlines . "no") (:noweb . "no") (:padline . "") (:result-params "replace"
"output" "raw") (:result-type . output) (:results . "replace output raw") (
:rowname-names) (:session . "none") (:shebang . "") (:tangle . "no")) ""
nil 0 1) block nil "a01854650514fd2cec7ce6957a4622b52118fcd3")
  org-babel-exp-do-export(("scheme" "(display \"Hello Scheme in OrgMode\")"
((:cache . "no") (:colname-names) (:comments . "") (:exports . "results")
(:hlines . "no") (:noweb . "no") (:padline . "") (:result-params "replace"
"output" "raw") (:result-type . output) (:results . "replace output raw"$
(:rowname-names) (:session . "none") (:shebang . "") (:tangle . "no")) ""
nil 0 1) block "a01854650514fd2cec7ce6957a4622b52118fcd3")
  org-babel-exp-src-block(("scheme" ":exports" "results" ":results"
"output" "raw"))
  org-babel-exp-process-buffer()
  org-export-execute-babel-code()
  org-export-as(html nil nil nil nil)
  org-export-to-file(html "./test.html" nil nil nil nil nil)
  org-html-export-to-html()
  call-interactively(org-html-export-to-html nil nil)
  command-execute(org-html-export-to-html)
  command-line-1(("--eval=(load \"~/.emacs.d/init.el\")" "/home/kdr2/
test.org" "-f" "org-html-export-to-html"))
  command-line()
  normal-top-level()



On Thu, Apr 10, 2014 at 7:22 PM, Oleh <ohwoeowho@gmail.com> wrote:

> > Version of  geiser I installed: geiser-20140326.951, If it has been
> changed,
> > it must be changed in the past 2 weeks ...
> >
>
> That's exactly the version that I have.
> Which org-mode are you using?
>



-- 
-- 

KDr2, http://kdr2.com

[-- Attachment #2: Type: text/html, Size: 5614 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-02  3:48 [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode KDr2
  2014-04-08 13:56 ` KDr2
@ 2014-04-11  2:45 ` Eric Schulte
  2014-04-11  5:18   ` KDr2
  1 sibling, 1 reply; 16+ messages in thread
From: Eric Schulte @ 2014-04-11  2:45 UTC (permalink / raw)
  To: KDr2; +Cc: emacs-orgmode

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 <killy.draw@gmail.com> 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-11  2:45 ` Eric Schulte
@ 2014-04-11  5:18   ` KDr2
  2014-04-11 19:18     ` Eric Schulte
  0 siblings, 1 reply; 16+ messages in thread
From: KDr2 @ 2014-04-11  5:18 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1664 bytes --]

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 <killy.draw@gmail.com> 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

[-- Attachment #1.2: Type: text/html, Size: 3121 bytes --]

[-- Attachment #2: 0001-lisp-ob-scheme.el-Fix-scheme-code-blocks-execution-e.patch --]
[-- Type: text/x-patch, Size: 2378 bytes --]

From fe5549f3f48acf9b51aeb3706eb8dd3d76ab18c1 Mon Sep 17 00:00: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 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)
-- 
1.9.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-11  5:18   ` KDr2
@ 2014-04-11 19:18     ` Eric Schulte
  2014-04-12  8:13       ` KDr2
  0 siblings, 1 reply; 16+ messages in thread
From: Eric Schulte @ 2014-04-11 19:18 UTC (permalink / raw)
  To: KDr2; +Cc: emacs-orgmode

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 <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 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 <killy.draw@gmail.com> 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 <killy.draw@gmail.com>
> 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-11 19:18     ` Eric Schulte
@ 2014-04-12  8:13       ` KDr2
  2014-04-12 14:12         ` Eric Schulte
  0 siblings, 1 reply; 16+ messages in thread
From: KDr2 @ 2014-04-12  8:13 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 6538 bytes --]

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)
----

And the new patch is attached.

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.

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 #'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 <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 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 <killy.draw@gmail.com> 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 <killy.draw@gmail.com>
> > 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

[-- Attachment #1.2: Type: text/html, Size: 9691 bytes --]

[-- Attachment #2: 0001-lisp-ob-scheme.el-Fix-scheme-code-blocks-execution-e.patch --]
[-- Type: text/x-patch, Size: 2447 bytes --]

From f20949e18314977bfa3c2ec1a59fb1e7b3269cbd Mon Sep 17 00:00:00 2001
From: KDr2 <killy.draw@gmail.com>
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)
-- 
1.9.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-12  8:13       ` KDr2
@ 2014-04-12 14:12         ` Eric Schulte
  2014-05-22 12:45           ` KDr2
  0 siblings, 1 reply; 16+ messages in thread
From: Eric Schulte @ 2014-04-12 14:12 UTC (permalink / raw)
  To: KDr2; +Cc: emacs-orgmode

KDr2 <killy.draw@gmail.com> 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 <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 #'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 <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 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 <killy.draw@gmail.com> 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 <killy.draw@gmail.com>
>> > 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 <killy.draw@gmail.com>
> 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
  2014-04-12 14:12         ` Eric Schulte
@ 2014-05-22 12:45           ` KDr2
  0 siblings, 0 replies; 16+ messages in thread
From: KDr2 @ 2014-05-22 12:45 UTC (permalink / raw)
  Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 10770 bytes --]

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 <schulte.eric@gmail.com>wrote:

> KDr2 <killy.draw@gmail.com> 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 <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 #'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 <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 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 <killy.draw@gmail.com> 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 <killy.draw@gmail.com>
> >> > 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 <killy.draw@gmail.com>
> > 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

[-- Attachment #2: Type: text/html, Size: 15853 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2014-05-22 12:45 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-02  3:48 [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode KDr2
2014-04-08 13:56 ` KDr2
2014-04-10  8:27   ` Oleh
2014-04-10  8:36     ` KDr2
2014-04-10  8:55       ` Oleh
2014-04-10  9:02         ` KDr2
2014-04-10 10:54           ` Oleh
2014-04-10 11:00             ` KDr2
2014-04-10 11:22               ` Oleh
2014-04-10 11:32                 ` KDr2
2014-04-11  2:45 ` Eric Schulte
2014-04-11  5:18   ` KDr2
2014-04-11 19:18     ` Eric Schulte
2014-04-12  8:13       ` KDr2
2014-04-12 14:12         ` Eric Schulte
2014-05-22 12:45           ` KDr2

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).