emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
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,

#+begin_src elisp :results none :exports none
(ow-babel-eval "neru-simplified")

The implementation I use is included below and is source dfrom

(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
      (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)
              ;; FIXME optionally raise errors on failure here !?
              (advice-add #'org-babel-insert-result :around
          (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)
      (apply fun args))))

      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:

  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 \


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