org-sbe: Allow quoting string values
* lisp/ob-table.el (org-sbe): Allow quoting string values of variables with "$". Update the docstring. * testing/lisp/test-ob-table.el (test-ob-table/sbe): Add test. Do not use `org-test-at-id' in favor of more illustrative `org-test-with-temp-text'. The latter does not force users to search the ID in reference Org file. * testing/examples/babel.org (calling code blocks from inside table): Remove unused example. Reported-by: 赵一宇 <zhyznd@163.com> Link: https://orgmode.org/list/40651be0.3e3b.1867971e644.Coremail.zhyznd@163.com
This commit is contained in:
parent
cbab9ebf55
commit
2e883b21a7
|
@ -87,18 +87,20 @@ is the equivalent of the following source code block:
|
|||
results
|
||||
#+end_src
|
||||
|
||||
NOTE: The quotation marks around the function name,
|
||||
`source-block', are optional.
|
||||
The quotation marks around the function name, `source-block', are
|
||||
optional.
|
||||
|
||||
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\").
|
||||
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\"). \"$\" will also force interpreting
|
||||
string value literally: $\"value\" will refer to a string, not a
|
||||
source block name.
|
||||
|
||||
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
|
||||
the header argument which can then be passed before all variables
|
||||
as shown in the example below.
|
||||
It is also possible to pass header arguments to the code block. In
|
||||
this case a table cell should hold the string value of the header
|
||||
argument which can then be passed before all variables as shown in the
|
||||
example below.
|
||||
|
||||
| 1 | 2 | :file nothing.png | nothing.png |
|
||||
#+TBLFM: @1$4=\\='(org-sbe test-sbe $3 (x $1) (y $2))"
|
||||
|
@ -117,7 +119,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))))
|
||||
|
|
|
@ -125,16 +125,6 @@
|
|||
(pascals-triangle n)
|
||||
#+end_src
|
||||
|
||||
* calling code blocks from inside table
|
||||
:PROPERTIES:
|
||||
:ID: 6d2ff4ce-4489-4e2a-9c65-e3f71f77d975
|
||||
:END:
|
||||
|
||||
#+name: take-sqrt
|
||||
#+begin_src emacs-lisp :var n=9
|
||||
(sqrt n)
|
||||
#+end_src
|
||||
|
||||
* executing an lob call line
|
||||
:PROPERTIES:
|
||||
:header-args: :results silent
|
||||
|
|
|
@ -26,8 +26,24 @@
|
|||
|
||||
(ert-deftest test-ob-table/sbe ()
|
||||
"Test that `sbe' can be used to call code blocks from inside tables."
|
||||
(org-test-at-id "6d2ff4ce-4489-4e2a-9c65-e3f71f77d975"
|
||||
(should (equal "2.0" (org-sbe take-sqrt (n "4"))))))
|
||||
(org-test-with-temp-text
|
||||
"#+name: take-sqrt
|
||||
#+begin_src emacs-lisp :var n=9
|
||||
(sqrt n)
|
||||
#+end_src"
|
||||
;; Symbol src block name.
|
||||
(should (equal "2.0" (org-sbe take-sqrt (n "4"))))
|
||||
;; String src block name.
|
||||
(should (equal "2.0" (org-sbe "take-sqrt" (n "4")))))
|
||||
(org-test-with-temp-text
|
||||
"#+name: identity
|
||||
#+begin_src emacs-lisp :var x=1
|
||||
x
|
||||
#+end_src"
|
||||
;; Escape quotes.
|
||||
(should
|
||||
(equal "123°34'23.34\"otherthing"
|
||||
(org-sbe identity (x $"123°34'23.34\"otherthing"))))))
|
||||
|
||||
(provide 'test-ob-table)
|
||||
|
||||
|
|
Loading…
Reference in New Issue