Ian Kelling <i...@iankelling.org> writes:

> Achim Gratz <strom...@nexgo.de> writes:
>
>> Ian Kelling writes:
>>> org-babel table output uses different formatting for a list of lists,
>>> but detects it incorrectly causing an error, as in this example:
>>> #+begin_src emacs-lisp 
>>> '((1) 2)
>>> #+end_src
>>
>> So this isn't a proper table, what do you expect to happen?
>
> I expect to be able to emacs -q, make an org mode buffer containing 
> that block, do ctrl-c c on it, and not have an error message pop up and
> fail to have any output. What is improper about it? Would it be better
> if org did not try to format it as a table?

Actually, I see what you mean by improper.

>
>>
>>> -                                      (and (listp (car result))
>>> -                                           (listp (cdr (car result)))))
>>> +                                      (cl-every 'listp result))
>>
>> This is wrong, because a table can come with any number of 'hline
>> symbols, so ostensibly not every element will be a listp.
>
> Yes, I agree. It will have to test if elements are listp or hline. 
>
>
>> Besides, you
>> can't use cl-every unless Org drops backwards compatibility with older
>> Emacsen or mandates cl-lib to be present.  Even then, you'd also need to
>> require cl-extra.
>
> I forgot about the multiple parts of cl. I originally wrote it without,
> and can change it.

Below is a patch that addresses the 2 previously mentioned
problems. 

-- >8 --
Subject: [PATCH] Fix error prone babel table output format detection

* lisp/ob-core.el: Test that all elements are in a list are lists or
'hline instead of just the first.

org-babel table output uses different formatting for a list of lists,
but detects it incorrectly causing an error, as in this example:
#+begin_src emacs-lisp 
'((1) 2)
#+end_src
---
 lisp/ob-core.el |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 1348f04..b5b0bc7 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2184,9 +2184,16 @@ code ---- the results are extracted in the syntax of the 
source
                 ((funcall 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)))))
+                                    (if (let ((len (length result))
+                                              (proper t)
+                                              (i 0)
+                                              elem)
+                                          (while (and proper (< i len ))
+                                            (setq elem (nth i result))
+                                            (unless (or (listp elem) (eq elem 
'hline))
+                                              (setq proper nil))
+                                            (setq i (1+ i)))
+                                          proper)
                                       result (list result))
                                   '(:fmt (lambda (cell) (format "%s" cell)))) 
"\n"))
                  (goto-char beg) (when (org-at-table-p) (org-table-align)))
-- 
1.7.10.4



Reply via email to