emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Daniele Nicolodi <daniele@grinta.net>
To: Org Mode List <emacs-orgmode@gnu.org>
Subject: How is org-sbe supposed to work?
Date: Fri, 13 Nov 2020 15:39:33 +0100	[thread overview]
Message-ID: <7de3bd69-4604-302a-b6d4-4e190f23bdb8@grinta.net> (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:

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

#+call: example(x=2)

: x:2

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

However, strings are not handled correctly:

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

: 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

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

: 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.


             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

Reply instructions:

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 \
    --in-reply-to=7de3bd69-4604-302a-b6d4-4e190f23bdb8@grinta.net \
    --to=daniele@grinta.net \
    --cc=emacs-orgmode@gnu.org \


* 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).