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
                      ;; limit to call, src
  (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)))))

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,

#+begin_src emacs-lisp :noweb yes
(defun my/org-kill-expanded-block ()
  (kill-new (car

;; META test it! {C-c C-v M-w}
(define-key org-babel-map (kbd "M-w") 'my/org-kill-expanded-block)

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

  Samuel Culpepper

Attachment: signature.asc
Description: PGP signature

Reply via email to