summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2011-11-15 15:30:35 -0700
committerEric Schulte <schulte.eric@gmail.com>2011-11-15 15:30:35 -0700
commit8114cf2bc460fc85d07e3141815b90a1c9eb41fb (patch)
tree28a5c7e71f43095638529431d913e528002c7bd5
parentf8d8f81e79d8d241b5226803158075b78ff903df (diff)
downloadorg-mode-8114cf2bc460fc85d07e3141815b90a1c9eb41fb.tar.gz
Gracefully handle results which are neither lists nor strings.
* lisp/ob.el (org-babel-insert-result): Gracefully handle results which are neither lists nor strings.
-rw-r--r--lisp/ob.el74
1 files changed, 39 insertions, 35 deletions
diff --git a/lisp/ob.el b/lisp/ob.el
index 100d2d1..efcd8da 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -1742,42 +1742,45 @@ code ---- the results are extracted in the syntax of the source
((member "prepend" result-params)))) ; already there
(setq results-switches
(if results-switches (concat " " results-switches) ""))
- ;; insert results based on type
- (cond
- ;; do nothing for an empty result
- ((= (length result) 0))
- ;; insert a list if preferred
- ((member "list" result-params)
- (insert
- (org-babel-trim
- (org-list-to-generic
- (cons 'unordered
- (mapcar
- (lambda (el) (list nil (if (stringp el) el (format "%S" el))))
- (if (listp result) result (list result))))
- '(:splicep nil :istart "- " :iend "\n")))
- "\n"))
- ;; assume the result is a table if it's not a string
- ((not (stringp result))
- (goto-char beg)
- (insert (concat (orgtbl-to-orgtbl
- (if (or (eq 'hline (car result))
- (and (listp (car result))
- (listp (cdr (car result)))))
- result (list result))
- '(:fmt (lambda (cell) (format "%s" cell)))) "\n"))
- (goto-char beg) (when (org-at-table-p) (org-table-align)))
- ((member "file" result-params)
- (when inlinep (goto-char inlinep))
- (insert result))
- (t (goto-char beg) (insert result)))
- (when (listp result) (goto-char (org-table-end)))
- (setq end (point-marker))
- ;; possibly wrap result
(flet ((wrap (start finish)
(goto-char beg) (insert (concat start "\n"))
(goto-char end) (insert (concat finish "\n"))
- (setq end (point-marker))))
+ (setq end (point-marker)))
+ (proper-list-p (it) (and (listp it) (null (cdr (last it))))))
+ ;; insert results based on type
+ (cond
+ ;; do nothing for an empty result
+ ((null result))
+ ;; insert a list if preferred
+ ((member "list" result-params)
+ (insert
+ (org-babel-trim
+ (org-list-to-generic
+ (cons 'unordered
+ (mapcar
+ (lambda (el) (list nil (if (stringp el) el (format "%S" el))))
+ (if (listp result) result (list result))))
+ '(:splicep nil :istart "- " :iend "\n")))
+ "\n"))
+ ;; assume the result is a table if it's not a string
+ ((proper-list-p result)
+ (goto-char beg)
+ (insert (concat (orgtbl-to-orgtbl
+ (if (or (eq 'hline (car result))
+ (and (listp (car result))
+ (listp (cdr (car result)))))
+ result (list result))
+ '(:fmt (lambda (cell) (format "%s" cell)))) "\n"))
+ (goto-char beg) (when (org-at-table-p) (org-table-align)))
+ ((and (listp result) (not (proper-list-p result)))
+ (insert (format "%s\n" result)))
+ ((member "file" result-params)
+ (when inlinep (goto-char inlinep))
+ (insert result))
+ (t (goto-char beg) (insert result)))
+ (when (proper-list-p result) (goto-char (org-table-end)))
+ (setq end (point-marker))
+ ;; possibly wrap result
(cond
((member "html" result-params)
(wrap "#+BEGIN_HTML" "#+END_HTML"))
@@ -1794,7 +1797,8 @@ code ---- the results are extracted in the syntax of the source
(when (and (stringp result) (not (member "file" result-params)))
(org-babel-examplize-region beg end results-switches))
(wrap "#+BEGIN_RESULT" "#+END_RESULT"))
- ((and (stringp result) (not (member "file" result-params)))
+ ((and (not (proper-list-p result))
+ (not (member "file" result-params)))
(org-babel-examplize-region beg end results-switches)
(setq end (point)))))
;; possibly indent the results to match the #+results line
@@ -1803,7 +1807,7 @@ code ---- the results are extracted in the syntax of the source
(not (and (listp result)
(member "append" result-params))))
(indent-rigidly beg end indent))))
- (if (= (length result) 0)
+ (if (null result)
(if (member "value" result-params)
(message "Code block returned no value.")
(message "Code block produced no output."))