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

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