summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2010-12-20 18:45:07 +0000
committerDan Davison <dandavison7@gmail.com>2010-12-21 14:19:24 +0000
commit366abc6175f7407f41ec1007aad51fdaebd4cba5 (patch)
tree125dfaab2774e1902e818a288df797bd263b0010
parent70349cd0c27c9993688bd47748806eafb8db204f (diff)
downloadorg-mode-366abc6175f7407f41ec1007aad51fdaebd4cba5.tar.gz
ob: Refactoring
* lisp/ob.el (org-babel-format-result): New function to format results of src block execution. (org-babel-execute-src-block): Use `org-babel-format-result' when writing to file. (org-babel-open-src-block-result): Use `org-babel-format-result' when displaying results in a buffer; name results buffer differently.
-rw-r--r--lisp/ob.el43
1 files changed, 20 insertions, 23 deletions
diff --git a/lisp/ob.el b/lisp/ob.el
index 6b2276c..671fef3 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -418,15 +418,8 @@ block."
(when result
(with-temp-file (cdr (assoc :file params))
(insert
- (if (listp result)
- ;; table result
- (orgtbl-to-generic
- result
- (list
- :sep (or (cdr (assoc :sep (nth 2 info))) "\t")
- :fmt 'echo-res))
- ;; scalar result
- (echo-res result)))))
+ (org-babel-format-result
+ result (cdr (assoc :sep (nth 2 info)))))))
(setq result (cdr (assoc :file params)))))
(org-babel-insert-result
result result-params info new-hash indent lang)
@@ -596,20 +589,10 @@ results already exist."
(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))))))
+ (pop-to-buffer (get-buffer-create "*Org-Babel Results*"))
+ (delete-region (point-min) (point-max))
+ (insert (org-babel-format-result (org-babel-read-result)
+ (cdr (assoc :sep (nth 2 info))))))
t))))
;;;###autoload
@@ -1385,6 +1368,20 @@ If the path of the link is a file path it is expanded using
(expand-file-name (match-string 2 raw))))
(t raw))))
+(defun org-babel-format-result (result &optional sep)
+ "Format RESULT for writing to file."
+ (flet ((echo-res (result)
+ (if (stringp result) result (format "%S" result))))
+ (if (listp result)
+ ;; table result
+ (orgtbl-to-generic
+ result
+ (list
+ :sep (or sep "\t")
+ :fmt 'echo-res))
+ ;; scalar result
+ (echo-res result))))
+
(defun org-babel-insert-result
(result &optional result-params info hash indent lang)
"Insert RESULT into the current buffer.