org-babel-script-escape: Turn empty lists into nil

* lisp/ob-core.el: Translate (), {}, and [] to nil.
* testing/lisp/test-ob.el (test-ob/script-escape): Add tests.

Reported-by: Jonas Bernoulli <jonas@bernoul.li>
Link: https://list.orgmode.org/87v8opfhk1.fsf@bernoul.li/T/#u
This commit is contained in:
Ihor Radchenko 2022-10-12 19:46:14 +08:00
parent 416c839c59
commit 4c0641837c
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 6 additions and 1 deletions

View File

@ -3124,7 +3124,7 @@ block but are passed literally to the \"example-block\"."
(error "`org-babel-script-escape' expects a string"))
(let ((escaped
(cond
((and (> (length str) 2)
((and (>= (length str) 2)
(or (and (string-equal "[" (substring str 0 1))
(string-equal "]" (substring str -1)))
(and (string-equal "{" (substring str 0 1))

View File

@ -1962,6 +1962,11 @@ default-directory
(org-babel-execute-src-block)))))
(ert-deftest test-ob/script-escape ()
;; Empty list.
(should (equal nil (org-babel-script-escape "[]")))
(should (equal nil (org-babel-script-escape "()")))
(should (equal nil (org-babel-script-escape "'()")))
(should (equal nil (org-babel-script-escape "{}")))
;; Delimited lists of numbers
(should (equal '(1 2 3)
(org-babel-script-escape "[1 2 3]")))