From: Tom Gillespie <tgbugs@gmail.com>
To: Org Mode List <emacs-orgmode@gnu.org>
Cc: George Mauer <gmauer@gmail.com>
Subject: Re: call blocks as a function from inside elisp code
Date: Wed, 19 Jan 2022 15:00:14 -0500 [thread overview]
Message-ID: <CA+G3_PPEx9XGSSxWvw__9isbYp0-i_HZYaiBVevMP=VksZpy_w@mail.gmail.com> (raw)
In-Reply-To: <87bl07oev3.fsf@ucl.ac.uk>
Hi George,
Here is an example of how I call nested elisp and python. The
python block is an input argument to the elisp block in this case, but
the python block could be called directly as well. I'm not sure how to
pass arguments to the block from inside elisp via org-babel-eval
though, that seems like it would require some deeper
tampering/advising of functions. Best,
Tom
https://github.com/SciCrunch/sparc-curation/blame/master/docs/queries.org#L1704-L1707
#+begin_src elisp :results none :exports none
(ow-babel-eval "neru-simplified")
#+end_src
The implementation I use is included below and is source dfrom
https://github.com/tgbugs/orgstrap/blob/bc981b957967be8d872c08be9ba7f2dbde5caf1d/ow.el#L786-L803
(defun ow-babel-eval (block-name &optional universal-argument)
"Use to confirm running a chain of dependent blocks starting with BLOCK-NAME.
This retains single confirmation at the entry point for the block."
;; TODO consider a header arg for a variant of this in org babel proper
(interactive "P")
(let ((org-confirm-babel-evaluate (lambda (_l _b) nil))) ;; FIXME
TODO set messages buffer size to nil
(save-excursion
(when (org-babel-find-named-block block-name)
;; goto won't raise an error which results in the block where
;; `ow-confirm-once' is being used being called an infinite
;; number of times and blowing the stack
(org-babel-goto-named-src-block block-name)
(unwind-protect
(progn
;; FIXME optionally raise errors on failure here !?
(advice-add #'org-babel-insert-result :around
#'ow--results-silent)
(org-babel-execute-src-block))
(advice-remove #'org-babel-insert-result #'ow--results-silent))))))
(defun ow--results-silent (fun &rest args)
"Whoever named the original version of this has a strange sense of humor."
;; so :results silent, which is what org babel calls between vars
;; set automatically is completely broken when one block calls another
;; there likely needs to be an internal gensymed value that babel blocks
;; can pass to eachother so that a malicious user cannot actually slience
;; values, along with an option to still print, but until then we have this
(let ((result (car args))
(result-params (cadr args)))
(if (member "silent" result-params)
result
(apply fun args))))
prev parent reply other threads:[~2022-01-19 20:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-19 15:56 call blocks as a function from inside elisp code George Mauer
2022-01-19 16:43 ` Eric S Fraga
2022-01-19 20:00 ` Tom Gillespie [this message]
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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
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='CA+G3_PPEx9XGSSxWvw__9isbYp0-i_HZYaiBVevMP=VksZpy_w@mail.gmail.com' \
--to=tgbugs@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=gmauer@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* 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
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
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).