summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Panteleev <git@thecybershadow.net>2018-03-19 00:23:13 +0000
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-03-20 00:01:09 +0100
commitc9d617b32278c04e114bd7c6375ca53636a005ba (patch)
treec7e3e76295b201665a02207a3f0beffbc2547f7f
parent5b59e16c9ea7ffa04ab71f8d37f8b8677e89f735 (diff)
downloadorg-mode-c9d617b32278c04e114bd7c6375ca53636a005ba.tar.gz
ob-table: Fix org-sbe's handling of list arguments
* ob-table.el (org-sbe): Add an explicit case for handling list arguments. This avoids doing the wrong thing (%s-formatting a list, thus losing syntax like double-quotes). This enables passing org-table ranges through org-sbe in a simple and correct manner. * test-ob-table.el: Add test.
-rw-r--r--lisp/ob-table.el17
-rw-r--r--testing/lisp/test-ob-table.el23
2 files changed, 34 insertions, 6 deletions
diff --git a/lisp/ob-table.el b/lisp/ob-table.el
index 105aca5..17810dd 100644
--- a/lisp/ob-table.el
+++ b/lisp/ob-table.el
@@ -132,12 +132,17 @@ as shown in the example below.
"("
(mapconcat
(lambda (var-spec)
- (if (> (length (cdr var-spec)) 1)
- (format "%S='%S"
- (car var-spec)
- (mapcar #'read (cdr var-spec)))
- (format "%S=%s"
- (car var-spec) (cadr var-spec))))
+ (cond
+ ((> (length (cdr var-spec)) 1)
+ (format "%S='%S"
+ (car var-spec)
+ (mapcar #'read (cdr var-spec))))
+ ((stringp (cadr var-spec))
+ (format "%S=%s"
+ (car var-spec) (cadr var-spec)))
+ (t
+ (format "%S=%S"
+ (car var-spec) (cadr var-spec)))))
',variables ", ")
")")))))
(org-babel-execute-src-block
diff --git a/testing/lisp/test-ob-table.el b/testing/lisp/test-ob-table.el
index 3d9b1d1..fb6d057 100644
--- a/testing/lisp/test-ob-table.el
+++ b/testing/lisp/test-ob-table.el
@@ -52,6 +52,29 @@
1
"#+TBLFM: $2 = '(org-sbe identity (x $$1))"))
+(ert-deftest test-ob-table/sbe-list ()
+ "Test that `org-sbe' can correctly handle ranges as lists."
+ (org-test-table-target-expect
+ "
+#+name: concat
+#+begin_src emacs-lisp :eval yes
+ (mapconcat #'identity x \"\")
+#+end_src
+
+| foo | bar | replace |
+"
+ "
+#+name: concat
+#+begin_src emacs-lisp :eval yes
+ (mapconcat #'identity x \"\")
+#+end_src
+
+| foo | bar | foobar |
+"
+ 1
+ "#+TBLFM: $3 = '(org-sbe concat (x (list $1..$2)))"
+ "#+TBLFM: $3 = '(org-sbe concat (x $ (list $1..$2)))"))
+
(provide 'test-ob-table)
;;; test-ob-table.el ends here