Ken Mankoff <mank...@gmail.com> writes:

> Is it possible to set variables using Org Babel inside screen, which does not 
> support ":var" header args? I'd actually lke a double-nested screen over ssh, 
> and the ability to re-use Babel code blocks under different headings, using 
> header args or PROPERTIES to change variables. That is, something like:

Yes.

> ...
> #+NAME: get-prop
> #+BEGIN_SRC emacs-lisp :var prop="FOO" :noweb yes
> (org-macro--get-property prop "")
> #+END_SRC
>
> #+NAME: inject_vars
> #+BEGIN_SRC shell :noweb yes
> # echo <<get-prop(prop="FOO")>> # testing
> echo export FOO=<<get-prop(prop="FOO")>>
> echo export BAR=<<get-prop(prop="BAR")>>
> echo export BAZ=<<get-prop(prop="BAZ")>>
> #+END_SRC

This did not work as you expected because noweb evaluates code block
with point at that code block.

To get the property value at the code block where you expand noweb
reference, you need to compute the value in the arguments to the
reference. Something like

#+name: identity
#+begin_src elisp :var x=""
x
#+end_src

...
echo export FOO=<<identity(x=(org-macro--get-property prop "FOO"))
...

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

Reply via email to