From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: [BUG][babel] ":result output table" doesn't work for python code blocks Date: Fri, 15 Apr 2011 10:13:40 -0600 Message-ID: <877hava3d8.fsf@gmail.com> References: <87k4ew2vfu.fsf@are.berkeley.edu> <87oc485jy3.fsf@gmail.com> <87hb9zyf79.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:43451) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QAlqh-0001ho-41 for emacs-orgmode@gnu.org; Fri, 15 Apr 2011 12:26:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QAlqc-0007AC-P2 for emacs-orgmode@gnu.org; Fri, 15 Apr 2011 12:26:23 -0400 Received: from mail-pv0-f169.google.com ([74.125.83.169]:34812) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QAlqc-0006qu-FP for emacs-orgmode@gnu.org; Fri, 15 Apr 2011 12:26:18 -0400 Received: by pvg4 with SMTP id 4so1547670pvg.0 for ; Fri, 15 Apr 2011 09:26:17 -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: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Eric S Fraga writes: > "Eric Schulte" 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 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-ob-octave-allow-collecting-tabular-results-when-resu.patch >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 --=-=-= Content-Type: text/plain -- Eric Schulte http://cs.unm.edu/~eschulte/ --=-=-=--