emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How is org-sbe supposed to work?


From: Daniele Nicolodi
Subject: How is org-sbe supposed to work?
Date: Fri, 13 Nov 2020 15:39:33 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.12.1

Hello,

I am trying to use the org-sbe macro to execute a code block with input
from an org table, however it does not work as I would expect it to work
and the code is cryptic enough for me to not being able to understand
what the intent was when it was written. I searched for tests in the
codebase that exercise this functionality, but I haven't found any:

daniele@black:~/src/org-mode$ grep org-sbe * -r
lisp/ob-table.el:;; `org-sbe' as so...
lisp/ob-table.el:;; #+TBLFM: $2='(org-sbe "fibbd" (n $1))
lisp/ob-table.el:(defmacro org-sbe (source-block &rest variables)
lisp/ob-table.el:So this `org-sbe' construct
lisp/ob-table.el: (org-sbe \"source-block\" (n $2) (m 3))
lisp/ob-table.el:#+TBLFM: @1$4=\\='(org-sbe test-sbe $3 (x $1) (y $2))"

How are variables passed to the code block supposed to be handled? The
macro docstring does not mention anything particular, thus I would
imagine they are handled just like in any other lisp code. However, this
does not seem to be the case.

In the case that the values are integers, all works as expected:

#+name: example
#+begin_src emacs-lisp :var x=1
(format "x:%S" x)
#+end_src

#+call: example(x=2)

#+RESULTS:
: x:2

| 1 | x:2 |
#+TBLFM: $2='(org-sbe "example" (x 2))

However, strings are not handled correctly:

#+call: example(x="baz")

#+RESULTS:
: x:"baz"

| 1 | #ERROR |
#+TBLFM: $2='(org-sbe "example" (x "baz"))

unless "double quoted":

| 1 | x:"baz" |
#+TBLFM: $2='(org-sbe "example" (x "\"baz\""))

and becomes an exercise in code injection if the string needs to come
from a table cell:

| baz | x:"baz" | x:"baz" |
#+TBLFM: $2='(org-sbe "example" (x \"$1\"));L
#+TBLFM: $3='(format "x:%S" $1)

Things get even more fun if the string value is the name of a code block:

#+name: foo
#+begin_src emacs-lisp :var x=1
nil
#+end_src

#+call: example(x="foo")

#+RESULTS:
: x:"foo"

| 1 |  |
#+TBLFM: $2='(org-sbe "example" (x "foo"))

as in this case, org-sbe actually tries to execute that code block
instead than using the literal string.

Should we come up with some tests highlighting the expected behavior of
org-sbe and make the implementation work accordingly?

Thank you.

Cheers,
Dan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]