From e0b79276789e47c268ac9a3dcc9b9bac93c1f251 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 20 Dec 2010 10:24:53 -0700 Subject: [PATCH] ob: :sep specifies table separator when opening or writing tabular results * lisp/ob.el (org-babel-execute-src-block): Allow specification of table separator with :sep header argument. (org-babel-open-src-block-result): Allow specification of table separator with :sep header argument. --- lisp/ob.el | 55 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/lisp/ob.el b/lisp/ob.el index 57092902e..0b3f77512 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -420,7 +420,9 @@ block." (if (stringp result) (insert result) (insert (orgtbl-to-generic - result '(:sep "\t" :fmt echo-res)))))) + result + (list :sep (or (cdr (assoc :sep params)) "\t") + :fmt 'echo-res)))))) (setq result (cdr (assoc :file params))))) (org-babel-insert-result result result-params info new-hash indent lang) @@ -577,29 +579,34 @@ source code block, otherwise return nil. With optional prefix argument RE-RUN the source-code block is evaluated even if results already exist." (interactive "P") - (when (org-babel-get-src-block-info) - (save-excursion - ;; go to the results, if there aren't any then run the block - (goto-char (or (and (not re-run) (org-babel-where-is-src-block-result)) - (progn (org-babel-execute-src-block) - (org-babel-where-is-src-block-result)))) - (end-of-line 1) - (while (looking-at "[\n\r\t\f ]") (forward-char 1)) - ;; open the results - (if (looking-at org-bracket-link-regexp) - ;; file results - (org-open-at-point) - (let ((results (org-babel-read-result))) - (flet ((echo-res (result) - (if (stringp result) result (format "%S" result)))) - (pop-to-buffer (get-buffer-create "org-babel-results")) - (delete-region (point-min) (point-max)) - (if (listp results) - ;; table result - (insert (orgtbl-to-generic results '(:sep "\t" :fmt echo-res))) - ;; scalar result - (insert (echo-res results)))))) - t))) + (let ((info (org-babel-get-src-block-info))) + (when info + (save-excursion + ;; go to the results, if there aren't any then run the block + (goto-char (or (and (not re-run) (org-babel-where-is-src-block-result)) + (progn (org-babel-execute-src-block) + (org-babel-where-is-src-block-result)))) + (end-of-line 1) + (while (looking-at "[\n\r\t\f ]") (forward-char 1)) + ;; open the results + (if (looking-at org-bracket-link-regexp) + ;; file results + (org-open-at-point) + (let ((results (org-babel-read-result))) + (flet ((echo-res (result) + (if (stringp result) result (format "%S" result)))) + (pop-to-buffer (get-buffer-create "org-babel-results")) + (delete-region (point-min) (point-max)) + (if (listp results) + ;; table result + (insert (orgtbl-to-generic + results + (list + :sep (or (cdr (assoc :sep (nth 2 info))) "\t") + :fmt 'echo-res))) + ;; scalar result + (insert (echo-res results)))))) + t)))) ;;;###autoload (defmacro org-babel-map-src-blocks (file &rest body)