summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2015-02-23 18:37:37 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2015-02-23 18:44:52 +0100
commitad7b7efcdc2e0803cbf0257bb2588c8e8e1cac29 (patch)
tree570f6ee4086d3642187229c01b1f561011f2e499
parente4da74c452f945274a8586be2803ed6b3a31b0bc (diff)
downloadorg-mode-ad7b7efcdc2e0803cbf0257bb2588c8e8e1cac29.tar.gz
ob-core: Fix inserting improper lists
* lisp/ob-core.el (org-babel-insert-result): Fix output when result is an improper list, which cannot be turned into a table. * testing/lisp/test-ob.el (test-ob/org-babel-insert-result--improper-lists): New test. Reported-by: Daniele Pizzolli <dan@toel.it> <http://permalink.gmane.org/gmane.emacs.orgmode/95348>
-rw-r--r--lisp/ob-core.el29
-rw-r--r--testing/lisp/test-ob.el12
2 files changed, 31 insertions, 10 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index a00b5a3..f2062ef 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2231,18 +2231,28 @@ INFO may provide the values of these header arguments (in the
(if (listp result) result (split-string result "\n" t))))
'(:splicep nil :istart "- " :iend "\n")))
"\n"))
- ;; assume the result is a table if it's not a string
- ((funcall proper-list-p result)
+ ;; Try hard to print RESULT as a table. Give up if
+ ;; it contains an improper list.
+ ((and (funcall proper-list-p result)
+ (org-every (lambda (e)
+ (or (atom e) (funcall proper-list-p e)))
+ result))
(goto-char beg)
(insert (concat (orgtbl-to-orgtbl
(if (org-every
- (lambda (el) (or (listp el) (eq el 'hline)))
+ (lambda (e)
+ (or (eq e 'hline) (listp e)))
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 (funcall proper-list-p result)))
- (insert (format "%s\n" result)))
+ result
+ (list result))
+ nil)
+ "\n"))
+ (goto-char beg)
+ (when (org-at-table-p) (org-table-align))
+ (goto-char (org-table-end)))
+ ;; Print verbatim a list that cannot be turned into
+ ;; a table.
+ ((listp result) (insert (format "%s\n" result)))
((member "file" result-params)
(when inlinep
(goto-char inlinep)
@@ -2254,11 +2264,10 @@ INFO may provide the values of these header arguments (in the
(insert (org-macro-escape-arguments
(org-babel-chomp result "\n"))))
(t (goto-char beg) (insert result)))
- (when (funcall proper-list-p result) (goto-char (org-table-end)))
(setq end (point-marker))
;; possibly wrap result
(cond
- (bad-inline-p) ; Do nothing.
+ (bad-inline-p) ; Do nothing.
((assoc :wrap (nth 2 info))
(let ((name (or (cdr (assoc :wrap (nth 2 info))) "RESULTS")))
(funcall wrap (concat "#+BEGIN_" name)
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index c5b5756..f52ff24 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -758,6 +758,18 @@ on two lines
": 2"
(buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
+(ert-deftest test-ob/org-babel-insert-result--improper-lists ()
+ "Test `org-babel-insert-result' with improper lists."
+ ;; Do not error when output is an improper list.
+ (should
+ (org-test-with-temp-text
+ "
+<point>#+BEGIN_SRC emacs-lisp
+'((1 . nil) (2 . 3))
+#+END_SRC
+"
+ (org-babel-execute-maybe) t)))
+
(ert-deftest test-ob/remove-inline-result ()
"Test `org-babel-remove-inline-result' honors whitespace."
(let*