Prechádzať zdrojové kódy

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
Ihor Radchenko 2 rokov pred
rodič
commit
4c0641837c
2 zmenil súbory, kde vykonal 6 pridanie a 1 odobranie
  1. 1 1
      lisp/ob-core.el
  2. 5 0
      testing/lisp/test-ob.el

+ 1 - 1
lisp/ob-core.el

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

+ 5 - 0
testing/lisp/test-ob.el

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