Daniel Bausch <[email protected]> writes:
>> What about simply
>>
>> (org-babel-call "foo"
>> :class "alice@db1"
>> :var hello "org")
>>
>> and making org-babel-call a macro (so that hello do not need to be
>> quoted)?
>
> Would it still compose as a macro? E.g., could I call one block
> assigning its variables using the result of two others?
Yes.
>> Alternative idea:
>>
>> (org-babel-call (foo "org")
>> :class "alice@db1)
>> (org-babel-call (foo :hello "org")
>> :class "alice@db1" :eval "yes")
>>
>> (foo :hello "org") will follow normal Elisp function semantics but call
>> src blocks. Header args specified as extra.
>>
>> A bit like `eval'.
>
> Looks (!) very good at first sight, but does it compose? Does it work
> with lisp variables and all kinds of values given as arguments?
Sure, it should. Macros have full control over which parts are evaluated
and which parts are not.
> I have a companion proposal ready which we might keep in mind before
> deciding on a sytnax for org-babel-call.
>
> It's currently called as (org-babel-result "block-name").
>
> It retrieves the current result from the named block similar to how it
> would be done if :cache yes were specified on that block. So it
> intentionally takes the current result from the buffer without
> recalculating a block. It can be used from within elisp blocks, of
> course, but also in a variable assignment inside a header argument,
> like:
>
> #+name: hello
> #+begin_src python
> print("hello world")
> #+end_src
>
> #+results:
> : hello world
>
> #+begin_src python :var hello=(org-babel-result "hello")
> print(hello)
> #+end_src
Why not just :var hello=hello[:cache yes]() +
(setq org-babel-update-intermediate 'cache)?
#+name: hello
#+begin_src python :results output
import time
time.sleep(5)
print("hello world")
#+end_src
#+RESULTS[218412b0c950223ebb964bc507ff4bb44d70d634]: hello
: hello world
#+begin_src python :var hello=hello[:cache yes]() :results output
print(hello)
#+end_src
#+RESULTS:
: hello world
> (org-babel-call "foo" positional1 positional2 :dir "/home/daniel")
What if you need to pass :dir or other keyword as value?
> (org-babel-call "bar" :var "var1" lisp-variable) ;; (1)
> (org-babel-call "xyz" :var "var2=ref[3]") ;; (2)
> (org-babel-call "zyx" (org-babel-result "query")) ;; (3)
>
> 1) Two non-keyword args after :var => assignment by value
> - I would rather not make the word after :var somehow magic
This may work.
> 2) Only one non-keyword arg after :var => assigment using
> org-babel-ref-resolve as usual in #+call
Looks like defeating the purpose of pluggable ELisp.
> 3) (org-babel-result "...") looks and composes similarly.
>>> #+call: foo("org") :class alice@db1
>>>
>>> #+call: foo("mode") :class bob@db2
>>
>> While it may be tempting to develop whole new concepts for Org,
>> especially when you can implement them with LLM, I strongly advice
>> trying built-in options and customizations first. Org (and Elisp) have
>> plenty of features that are flexible enough to fit many needs. Adding
>> new things will produce subtle (or not so subtle) bugs, sooner or later,
>> especially as you update to new Org version developed without your new
>> additions in mind.
>
> Org, especially Babel, has been my daily driver for more than 15 years
> now. That :class thing was born out of essential necessity. I couldn't
> do my work without it. I'm working with multiple databases and database
> users - often inside one Org node. Having to detail out all the
> required header arguments for the different database connections for
> every block would be unfeasable - let alone proper password handling.
> My configuration behind it transparently retrieves and caches the
> passwords, which are stored in an encrypted password store. Of course
> it might break with some update, but that would be a minor thing. Not
> having it would be worse. If you are interested, I can share the
> implementation.
You are free to open another thread on the topic.
--
Ihor Radchenko // yantar92,
Org mode maintainer,
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>