0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-29 18:36:26 +00:00

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>
This commit is contained in:
Nicolas Goaziou 2015-02-23 18:37:37 +01:00
parent e4da74c452
commit ad7b7efcdc
2 changed files with 31 additions and 10 deletions

View file

@ -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)

View file

@ -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*