From: Daniele Nicolodi <firstname.lastname@example.org>
To: Org Mode List <email@example.com>
Subject: How is org-sbe supposed to work?
Date: Fri, 13 Nov 2020 15:39:33 +0100 [thread overview]
Message-ID: <firstname.lastname@example.org> (raw)
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:
#+begin_src emacs-lisp :var x=1
(format "x:%S" x)
| 1 | x:2 |
#+TBLFM: $2='(org-sbe "example" (x 2))
However, strings are not handled correctly:
| 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:
#+begin_src emacs-lisp :var x=1
| 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?
next reply other threads:[~2020-11-13 14:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-13 14:39 Daniele Nicolodi [this message]
2020-11-13 21:56 ` How is org-sbe supposed to work? Daniele Nicolodi
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).