From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [PATCH] ob-scheme.el: Fix scheme code blocks execution error in batch mode Date: Fri, 11 Apr 2014 13:18:22 -0600 Message-ID: <87tx9zk5ln.fsf@gmail.com> References: <87sipky46c.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYhTm-0007bp-JB for emacs-orgmode@gnu.org; Fri, 11 Apr 2014 15:51:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WYhTi-000778-An for emacs-orgmode@gnu.org; Fri, 11 Apr 2014 15:51:14 -0400 Received: from mail-pb0-x22b.google.com ([2607:f8b0:400e:c01::22b]:64752) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYhTh-000771-VK for emacs-orgmode@gnu.org; Fri, 11 Apr 2014 15:51:10 -0400 Received: by mail-pb0-f43.google.com with SMTP id um1so5836135pbc.2 for ; Fri, 11 Apr 2014 12:51:08 -0700 (PDT) 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 To: KDr2 Cc: emacs-orgmode@gnu.org 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 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