[Top][All Lists]

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

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

From: Ihor Radchenko
Subject: [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, 16 Jul 2022 16:57:32 +0800

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

> Ihor Radchenko writes:
>> Can you provide more concrete examples?
>>> Some drawbacks:
>>>    + doesn't work for all languages (does work for LaTeX)
>> Which languages do not work?
> Most languages do not work. Using your proposed solution, what I'm
> trying to do is
> #+name:javascript-header
> #+begin_src javascript :tangle no
> some javascript, with \ and " to be escaped
> #+end_src
> #+name: string-escape
> #+begin_src emacs-lisp :var str="" :tangle no
> (prin1-to-string (string-trim-right str))
> #+end_src
> #+begin_src emacs-lisp :noweb yes :tangle yes
> (setq javascript-header <<string-escape(str=javascript-header)>>)
> #+end_src
> If you replace javascript with latex, it happens to work, because when
> org executes a latex block, it prints its content.
> The goal is to tangle to some lisp code whose purpose is to generate
> LaTeX/javascript code. Quite niche admittedly, though as you showed,
> it could also be used to string-escape documentation.

Thanks for providing an example!

The current behaviour of :var foo=name-of-src-block is assigning result
of evaluation. However, this behaviour is actually not documented.
16.4 Environment of a Code Block section of the manual only documents
uses like
#+BEGIN_SRC emacs-lisp :var length=table-length()
#+BEGIN_SRC emacs-lisp :var input=double(input=1)

#+BEGIN_SRC emacs-lisp :var length=table-length
is the same with
#+BEGIN_SRC emacs-lisp :var length=table-length()

Given that
#+BEGIN_SRC emacs-lisp :var x=literal-example

inserts the literal contents of the example block, I am voting to change
the current undocumented behaviour for assigning the code block

This will make the discussed example work while not restricting the
existing features.



reply via email to

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