forked from mirrors/org-mode
ob-core: Resolve named list references to simple lists
* lisp/ob-core.el (org-babel-read-list): Return a simple list instead of list of lists. Document this in the docstring. * testing/lisp/test-ob-java.el (ob-java/read-return-list): (ob-java/read-list-return-array): (ob-java/read-return-list-with-package): Fix tests assuming previous behavior. * testing/lisp/test-ob.el (test-ob/simple-variable-resolution): Add new tests. * etc/ORG-NEWS (List references in source block variable assignments are now proper lists): Document the change. This commit fixes the broken promise in the manual section 16.4 Environment of a Code Block where the named references to lists should be converted to simple lists consisting of the top-level items. The inconsistency existed for a while and possibly lurked into some third-party packages. So, announcement in NEWS is required. Reported-by: Alain.Cochard@unistra.fr Link: https://orgmode.org/list/87pmdqfao4.fsf@localhost
This commit is contained in:
parent
c72d5ee840
commit
b4e437f968
34
etc/ORG-NEWS
34
etc/ORG-NEWS
|
@ -778,6 +778,40 @@ If you prefer to keep the keybinding, you can add it back to
|
|||
(define-key org-mode-map (kbd "C-c SPC") #'org-table-blank-field)
|
||||
#+end_src
|
||||
|
||||
*** List references in source block variable assignments are now proper lists
|
||||
|
||||
List representation of named lists is now converted to a simple list
|
||||
as promised by the manual section [[info:org#Environment of a Code Block][org#Environment of a Code Block]].
|
||||
Previously, it was converted to a list of lists.
|
||||
|
||||
Before:
|
||||
|
||||
#+begin_src org
|
||||
,#+NAME: example-list
|
||||
- simple
|
||||
- not
|
||||
- nested
|
||||
- list
|
||||
|
||||
,#+BEGIN_SRC emacs-lisp :var x=example-list :results value
|
||||
(format "%S" x)
|
||||
,#+END_SRC
|
||||
|
||||
,#+RESULTS:
|
||||
: (("simple" (unordered ("not") ("nested"))) ("list"))
|
||||
#+end_src
|
||||
|
||||
After:
|
||||
|
||||
#+begin_src org
|
||||
,#+BEGIN_SRC emacs-lisp :var x=example-list :results value
|
||||
(format "%S" x)
|
||||
,#+END_SRC
|
||||
|
||||
,#+RESULTS:
|
||||
: ("simple" "list")
|
||||
#+end_src
|
||||
|
||||
** New features
|
||||
|
||||
*** New citation engine
|
||||
|
|
|
@ -2239,8 +2239,15 @@ Return nil if ELEMENT cannot be read."
|
|||
(org-table-to-lisp)))
|
||||
|
||||
(defun org-babel-read-list ()
|
||||
"Read the list at point into emacs-lisp."
|
||||
(mapcar (lambda (el) (org-babel-read el 'inhibit-lisp-eval))
|
||||
"Read the list at point into emacs-lisp.
|
||||
|
||||
Return the list of strings representing top level items:
|
||||
|
||||
(item1 item2 ...)
|
||||
|
||||
Only consider top level items. See Info node `(org)Environment of \
|
||||
a Code Block'."
|
||||
(mapcar (lambda (el) (org-babel-read (car el) 'inhibit-lisp-eval))
|
||||
(cdr (org-list-to-lisp))))
|
||||
|
||||
(defvar org-link-types-re)
|
||||
|
|
|
@ -379,8 +379,8 @@ return a;
|
|||
"#+begin_src java :dir 'nil :var a=java_list :results value silent
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
List<String> b = Arrays.asList(a.get(0).get(0),
|
||||
a.get(1).get(0));
|
||||
List<String> b = Arrays.asList(a.get(0),
|
||||
a.get(1));
|
||||
return b;
|
||||
#+end_src
|
||||
|
||||
|
@ -394,7 +394,7 @@ return b;
|
|||
"Read a list and return an array."
|
||||
(org-test-with-temp-text
|
||||
"#+begin_src java :dir 'nil :var a=java_list :results value silent
|
||||
String[] b = {a.get(0).get(0), a.get(1).get(0)};
|
||||
String[] b = {a.get(0), a.get(1)};
|
||||
return b;
|
||||
#+end_src
|
||||
|
||||
|
@ -411,8 +411,8 @@ return b;
|
|||
package pkg;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
List<String> b = Arrays.asList(a.get(0).get(0),
|
||||
a.get(1).get(0));
|
||||
List<String> b = Arrays.asList(a.get(0),
|
||||
a.get(1));
|
||||
return b;
|
||||
#+end_src
|
||||
|
||||
|
|
|
@ -203,6 +203,26 @@ list, then it should be treated as such; not as the symbol nil."
|
|||
(should (= 4 (org-babel-execute-src-block)))
|
||||
(forward-line 5)
|
||||
(should (string= ": 4" (buffer-substring
|
||||
(point-at-bol)
|
||||
(point-at-eol)))))
|
||||
;; Test reading lists.
|
||||
(org-test-with-temp-text-in-file "
|
||||
|
||||
#+NAME: example-list
|
||||
- simple
|
||||
- not
|
||||
- nested
|
||||
- list
|
||||
|
||||
<point>#+BEGIN_SRC emacs-lisp :var x=example-list
|
||||
(print x)
|
||||
#+END_SRC"
|
||||
|
||||
(should (equal '("simple" "list") (org-babel-execute-src-block)))
|
||||
(forward-line 5)
|
||||
(should (string=
|
||||
"| simple | list |"
|
||||
(buffer-substring
|
||||
(point-at-bol)
|
||||
(point-at-eol))))))
|
||||
|
||||
|
|
Loading…
Reference in New Issue