[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
org-babel-expand-call-block
From: |
Samuel Culpepper |
Subject: |
org-babel-expand-call-block |
Date: |
Tue, 25 Apr 2023 15:20:51 +0200 |
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
signature.asc
Description: PGP signature
- org-babel-expand-call-block,
Samuel Culpepper <=