emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [FR] Make :var foo=name-of-src-block assign the source block code in


From: Ihor Radchenko
Subject: Re: [FR] Make :var foo=name-of-src-block assign the source block code instead of currently assigned result of evaluation (was: [PATCH] Add :noweb-prefix and :noweb-trans babel header arguments)
Date: Sat, 23 Jul 2022 12:52:12 +0800

S├ębastien Miquel <sebastien.miquel@posteo.eu> writes:

> The uses are maybe too niche to warrant the breaking change. A syntax
> extension like
>   : var=block-id[]
> seems possible, even though brackets are already overloaded.

This sounds better. Using brackets will actually make a lot of sense.

Currently, we have roughly the following logic in the :var references:

- :var x=reference(<optional parameters>)
  will execute the reference and assign the returned value

- :var x=reference[<optional parameters>]
  will take the reference text representation, possibly process it
  according to the parameters, and return the processed text

  *this only works for tables*

- :var x=reference
  will perform some "default" action depending on the reference type.
  the action may be "execute" or "get text representation" for source
  blocks and others correspondingly.

Extending reference[...] syntax to all the element types will make
things consistent and allow future extensions if we decide to provide
"index" syntax for non-tables (code lines, function definitions?)

> One alternative is to only allow the syntax inside noweb brackets
> instead of generic variable arguments. I assume there'd be much less
> breakage. It would also makes sense to allow noweb references instead
> of block ids. We'd add support for
>   : <<babel-fn(var=noweb-ref)>>
> and <<babel-fn(var=block-id)>> would also insert the contents as a
> by-product.

This would still be a breaking change. And we will introduce
inconsistency between resolving noweb references and resolving :var
header args.

Moreover, resolving references is currently handled by the same code
inside :vars and noweb references. Changing this will complicate the
source code as well, IMHO increasing the maintenance burden too much.

> Do you have any example of use in mind, beyond my original one ?

For example, one may convert .el file commentary to Readme.org:

#+name: my-library
#+begin_src :tangle my-library.el
;; Commentary:
;; A lot of commentary
#+end_src

#+begin_src :exports results :var commentary=my-library[]
(convert-to-org-headlines commentary)
#+end_src

Best,
Ihor



reply via email to

[Prev in Thread] Current Thread [Next in Thread]