emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: KDr2 <killy.draw@gmail.com>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode
Date: Sat, 12 Apr 2014 16:13:25 +0800	[thread overview]
Message-ID: <CAHfjm6gykmR3E53hSJBMd3GwPEeCFxqHUNtg09u-0euGqOUySA@mail.gmail.com> (raw)
In-Reply-To: <87tx9zk5ln.fsf@gmail.com>


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


  reply	other threads:[~2014-04-12  8:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2014-04-12 14:12         ` Eric Schulte
2014-05-22 12:45           ` KDr2

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHfjm6gykmR3E53hSJBMd3GwPEeCFxqHUNtg09u-0euGqOUySA@mail.gmail.com \
    --to=killy.draw@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=schulte.eric@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).