[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org b4e437f968: ob-core: Resolve named list references
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org b4e437f968: ob-core: Resolve named list references to simple lists |
Date: |
Fri, 25 Nov 2022 20:57:53 -0500 (EST) |
branch: externals/org
commit b4e437f968771df9555f9306467846965857f632
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>
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
---
etc/ORG-NEWS | 34 ++++++++++++++++++++++++++++++++++
lisp/ob-core.el | 11 +++++++++--
testing/lisp/test-ob-java.el | 10 +++++-----
testing/lisp/test-ob.el | 26 +++++++++++++++++++++++---
4 files changed, 71 insertions(+), 10 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index f9f859bab9..63ff5d749c 100644
--- a/etc/ORG-NEWS
+++ b/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
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 1259909a02..3a07c10d50 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -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)
diff --git a/testing/lisp/test-ob-java.el b/testing/lisp/test-ob-java.el
index 07540ed74a..65b7259d35 100644
--- a/testing/lisp/test-ob-java.el
+++ b/testing/lisp/test-ob-java.el
@@ -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
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index 4beaecf7bd..e4090d6d8b 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -204,7 +204,27 @@ list, then it should be treated as such; not as the symbol
nil."
(forward-line 5)
(should (string= ": 4" (buffer-substring
(point-at-bol)
- (point-at-eol))))))
+ (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))))))
(ert-deftest test-ob/block-content-resolution ()
"Test block content resolution."
@@ -218,8 +238,8 @@ list, then it should be treated as such; not as the symbol
nil."
#+begin_src emacs-lisp :var four=four[]
(length (eval (car (read-from-string four))))
#+end_src"
- (org-babel-next-src-block 2)
- (should (= 4
(org-babel-execute-src-block)))))
+ (org-babel-next-src-block 2)
+ (should (= 4 (org-babel-execute-src-block)))))
(ert-deftest test-ob/cons-cell-as-variable ()
"Test that cons cell can be assigned as variable."
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/org b4e437f968: ob-core: Resolve named list references to simple lists,
ELPA Syncer <=