Merge branch 'maint'

This commit is contained in:
Nicolas Goaziou 2018-03-20 00:02:26 +01:00
commit 55d807f348
2 changed files with 59 additions and 7 deletions

View file

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

View file

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