From: Samuel Culpepper <samuel@samuelculpepper.com>
To: emacs-orgmode@gnu.org
Subject: org-babel-expand-call-block
Date: Tue, 25 Apr 2023 15:20:51 +0200 [thread overview]
Message-ID: <87leigm72k.fsf@samuelculpepper.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2656 bytes --]
Hi orgmode, I thought it would be nice share a little excursion into
babel's code expansion; nothing groundbreaking, and nobody asked, but it
may address a more comprehensive tangling, or maybe just some ergonomics
for copying code.
#+name: babel-lob-info
#+begin_src emacs-lisp :var ya="dooby"
(when-let* ((context (org-element-lineage
(org-element-context)
;; limit to call, src
'(inline-babel-call
babel-call
inline-src-block
src-block)
t)))
(cl-case (org-element-type context)
((or babel-call inline-babel-call)
(let ((info (org-babel-lob-get-info context)))
;; this setf is to convert the the 'call args to 'src args.
;;
;; call :: (:var . "ya=\"dooby\"")
;; src :: (:var ya . "dooby")
;;
;; in org proper 'org-babel-execute-src-block, this parameter
;; normalization also happens before the 'expand call
(let ((old-info (copy-tree info)))
(setf (nth 2 info)
(org-babel-process-params (nth 2 info)))
;; META if you're copying this to use, just return the car,
;; as :info-src, :info-call are just here for the demo
;;
(list (org-babel-expand-src-block nil info)
:info-src info
:info-call old-info))))
(t ;; META as above
(list (org-babel-expand-src-block)))))
#+end_src
You may try this out by calling the below, with the point on the line:
#+call: babel-lob-info(ya="scoooby") :results code
I use this primarily to template things -- mostly very repetitive SQL,
for data analysis -- over arbitrarily deep nowebs and call blocks, but
have always struggled to share the resulting artifact with non-emacs
users, or tangle such noweb-call-dynamic-variable monstrosities. I will
at some point (TM) look into the tangling story, so would welcome any
suggestions, but the former -- sharing -- is made rather pleasant,
interactively:
#+begin_src emacs-lisp :noweb yes
(defun my/org-kill-expanded-block ()
(interactive)
(kill-new (car
<<babel-lob-info>>
)))
;; META test it! {C-c C-v M-w}
(define-key org-babel-map (kbd "M-w") 'my/org-kill-expanded-block)
#+end_src
#+RESULTS:
: my/org-kill-expanded-block
LOB has been a staple tool for me, if you feel enthused, do read more
of these exploits in my literate config :: https://github.com/qzdl/rde/blob/ixy/master/examples/src/qzdl/configs.org#library-of-babel
--
Yours,
Samuel Culpepper
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
next reply other threads:[~2023-05-03 12:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-25 13:20 Samuel Culpepper [this message]
2023-05-08 20:01 ` org-babel-expand-call-block Ihor Radchenko
2023-06-14 8:36 ` org-babel-expand-call-block Samuel Culpepper
2023-06-14 12:27 ` org-babel-expand-call-block Ihor Radchenko
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=87leigm72k.fsf@samuelculpepper.com \
--to=samuel@samuelculpepper.com \
--cc=emacs-orgmode@gnu.org \
/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).