From 7477c3ac10d28342ccf993ea36b41ebfcab015ac Mon Sep 17 00:00:00 2001 From: Eric Schulte 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