emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-babel-expand-call-block
@ 2023-04-25 13:20 Samuel Culpepper
  2023-05-08 20:01 ` org-babel-expand-call-block Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Samuel Culpepper @ 2023-04-25 13:20 UTC (permalink / raw)
  To: emacs-orgmode

[-- 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 --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: org-babel-expand-call-block
  2023-04-25 13:20 org-babel-expand-call-block Samuel Culpepper
@ 2023-05-08 20:01 ` Ihor Radchenko
  2023-06-14  8:36   ` org-babel-expand-call-block Samuel Culpepper
  0 siblings, 1 reply; 4+ messages in thread
From: Ihor Radchenko @ 2023-05-08 20:01 UTC (permalink / raw)
  To: Samuel Culpepper; +Cc: emacs-orgmode

Samuel Culpepper <samuel@samuelculpepper.com> writes:

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

Do I understand correctly that you are trying to get #+calls to LOB
blocks expanded as usual via org-babel-expand-src-block?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: org-babel-expand-call-block
  2023-05-08 20:01 ` org-babel-expand-call-block Ihor Radchenko
@ 2023-06-14  8:36   ` Samuel Culpepper
  2023-06-14 12:27     ` org-babel-expand-call-block Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Samuel Culpepper @ 2023-06-14  8:36 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 423 bytes --]


> Do I understand correctly that you are trying to get #+calls to LOB
> blocks expanded as usual via org-babel-expand-src-block?

Sure, uniformity in "expansion" is the ideal case.

I use LOB pretty extensively, so this hack allows such uniformity along
the "kill-expanded-SRC".

Would you consider a patch to org-babel-expand-src-block which
generalizes in this manner?

-- 
Best regards,
Samuel Culpepper

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: org-babel-expand-call-block
  2023-06-14  8:36   ` org-babel-expand-call-block Samuel Culpepper
@ 2023-06-14 12:27     ` Ihor Radchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Ihor Radchenko @ 2023-06-14 12:27 UTC (permalink / raw)
  To: Samuel Culpepper; +Cc: emacs-orgmode

Samuel Culpepper <samuel@samuelculpepper.com> writes:

>> Do I understand correctly that you are trying to get #+calls to LOB
>> blocks expanded as usual via org-babel-expand-src-block?
>
> Sure, uniformity in "expansion" is the ideal case.
>
> I use LOB pretty extensively, so this hack allows such uniformity along
> the "kill-expanded-SRC".
>
> Would you consider a patch to org-babel-expand-src-block which
> generalizes in this manner?

We can generalize `org-babel-expand-src-block' and
`org-babel-expand-src-block-maybe'.

I am not sure about killing. We need to ask if other users are
interested in such functionality.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-14 12:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-25 13:20 org-babel-expand-call-block Samuel Culpepper
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

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