emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [BUG][babel] ":result output table" doesn't work for python code


From: Eric Schulte
Subject: Re: [O] [BUG][babel] ":result output table" doesn't work for python code blocks
Date: Fri, 15 Apr 2011 10:13:40 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Eric S Fraga <address@hidden> writes:

> "Eric Schulte" <address@hidden> writes:
>
> [...]
>
>> That said, I agree that in examples like yours above the returned value
>> should be a table given that the ":results table" is explicitly stated.
>> I've just pushed up a patch after which the following is possible.
>
> Eric,
>
> It would appear that this change you've made is only for python)?  Is
> there any chance of having the same for octave, please?  But only if it
> is easy to do as =:results output raw= with carefully formatted output
> does the job for me for the moment!
>

Hi Eric,

I do not have a local copy of octave, so I'm less confident making
changes to that file, but the attached patch attempts to make the same
changes in ob-octave which were made in ob-python.

Could you please test this patch for both external and session based
evaluation and let me know if it works (I'm more hopeful that the
external evaluation will work as expected than the session evaluation).

Once this is working I'll commit it to the core.

Thanks -- Eric

>From 7477c3ac10d28342ccf993ea36b41ebfcab015ac Mon Sep 17 00:00:00 2001
From: Eric Schulte <address@hidden>
Date: Fri, 15 Apr 2011 10:11:18 -0600
Subject: [PATCH] ob-octave: allow collecting tabular results when ":results 
output"

* lisp/ob-octave.el (org-babel-octave-evaluate-external-process): Dump
  output to temp file, and read results from that file as with ":results value".
  (org-babel-octave-evaluate-session): Read results from temporary
  file with both ":results output" and ":results value".
---
 lisp/ob-octave.el |   55 ++++++++++++++++++++++++++++------------------------
 1 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el
index 3430dea..064677e 100644
--- a/lisp/ob-octave.el
+++ b/lisp/ob-octave.el
@@ -164,18 +164,18 @@ value of the last statement in BODY, as elisp."
 
 (defun org-babel-octave-evaluate-external-process (body result-type matlabp)
   "Evaluate BODY in an external octave process."
-  (let ((cmd (if matlabp
+  (let ((tmp-file (org-babel-temp-file "octave-"))
+       (cmd (if matlabp
                 org-babel-matlab-shell-command
               org-babel-octave-shell-command)))
     (case result-type
-      (output (org-babel-eval cmd body))
-      (value (let ((tmp-file (org-babel-temp-file "octave-")))
-              (org-babel-eval
-               cmd
-               (format org-babel-octave-wrapper-method body
-                       (org-babel-process-file-name tmp-file 'noquote)
-                       (org-babel-process-file-name tmp-file 'noquote)))
-              (org-babel-octave-import-elisp-from-file tmp-file))))))
+      (output (with-temp-file tmp-file (insert (org-babel-eval cmd body))))
+      (value (org-babel-eval
+             cmd
+             (format org-babel-octave-wrapper-method body
+                     (org-babel-process-file-name tmp-file 'noquote)
+                     (org-babel-process-file-name tmp-file 'noquote)))))
+    (org-babel-octave-import-elisp-from-file tmp-file)))
 
 (defun org-babel-octave-evaluate-session
   (session body result-type &optional matlabp)
@@ -194,7 +194,8 @@ value of the last statement in BODY, as elisp."
                  (format org-babel-matlab-emacs-link-wrapper-method
                          body
                          (org-babel-process-file-name tmp-file 'noquote)
-                         (org-babel-process-file-name tmp-file 'noquote) 
wait-file) "\n")
+                         (org-babel-process-file-name tmp-file 'noquote)
+                         wait-file) "\n")
               (mapconcat
                #'org-babel-chomp
                (list (format org-babel-octave-wrapper-method
@@ -221,21 +222,25 @@ value of the last statement in BODY, as elisp."
                       org-babel-octave-eoe-output)
                     t full-body)
                  (insert full-body) (comint-send-input nil t)))) results)
-    (case result-type
-      (value
-       (org-babel-octave-import-elisp-from-file tmp-file))
-      (output
-       (progn
-        (setq results
-              (if matlabp
-                  (cdr (reverse (delq "" (mapcar
-                                          #'org-babel-octave-read-string
-                                          (mapcar #'org-babel-trim raw)))))
-                (cdr (member org-babel-octave-eoe-output
-                             (reverse (mapcar
-                                       #'org-babel-octave-read-string
-                                       (mapcar #'org-babel-trim raw)))))))
-        (mapconcat #'identity (reverse results) "\n"))))))
+    (if (or (member "code" result-params)
+           (member "pp" result-params)
+           (member "scalar" result-params)
+           (and (member "output" result-params)
+                (not (member "table" result-params))))
+       (progn
+         (setq results
+               (if matlabp
+                   (cdr (reverse (delq "" (mapcar
+                                           #'org-babel-octave-read-string
+                                           (mapcar #'org-babel-trim raw)))))
+                 (cdr (member org-babel-octave-eoe-output
+                              (reverse (mapcar
+                                        #'org-babel-octave-read-string
+                                        (mapcar #'org-babel-trim raw)))))))
+         (mapconcat #'identity (reverse results) "\n"))
+      (when (equal results-type 'output)
+       (with-temp-file tmp-file (insert raw)))
+      (org-babel-octave-import-elisp-from-file tmp-file))))
 
 (defun org-babel-octave-import-elisp-from-file (file-name)
   "Import data from FILE-NAME.
-- 
1.7.1

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]