瀏覽代碼

Merge branch 'maint'

Nicolas Goaziou 7 年之前
父節點
當前提交
55d807f348
共有 2 個文件被更改,包括 59 次插入7 次删除
  1. 14 7
      lisp/ob-table.el
  2. 45 0
      testing/lisp/test-ob-table.el

+ 14 - 7
lisp/ob-table.el

@@ -89,6 +89,8 @@ NOTE: By default, string variable names are interpreted as
 references to source-code blocks, to force interpretation of a
 cell's value as a string, prefix the identifier a \"$\" (e.g.,
 \"$$2\" instead of \"$2\" or \"$@2$2\" instead of \"@2$2\").
+This will not work with a range; instead, pass it as a list,
+e.g. (org-sbe fun (r (list $1..$2))).
 
 NOTE: It is also possible to pass header arguments to the code
 block.  In this case a table cell should hold the string value of
@@ -112,7 +114,7 @@ as shown in the example below.
 				      (prog1 nil (setq quote t))
 				    (prog1
 					(cond
-					 (quote (format "\"%s\"" el))
+					 (quote (format "%S" el))
 					 ((stringp el) (org-no-properties el))
 					 (t el))
 				      (setq quote nil))))
@@ -132,12 +134,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

+ 45 - 0
testing/lisp/test-ob-table.el

@@ -30,6 +30,51 @@
 ;;   (org-test-at-id "6d2ff4ce-4489-4e2a-9c65-e3f71f77d975"
 ;;     (should (= 2 (sbe take-sqrt (n "4"))))))
 
+(ert-deftest test-ob-table/sbe-quote ()
+  "Test that `org-sbe' can correctly handle cell values containing quotes."
+  (org-test-table-target-expect
+   "
+#+name: identity
+#+begin_src emacs-lisp :eval yes
+  x
+#+end_src
+
+| a\"b\"c | replace |
+"
+   "
+#+name: identity
+#+begin_src emacs-lisp :eval yes
+  x
+#+end_src
+
+| a\"b\"c | a\"b\"c |
+"
+   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