emacs-orgmode
[Top][All Lists]
Advanced

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

Re: Sharing variables between source blocks without session


From: Loris Bennett
Subject: Re: Sharing variables between source blocks without session
Date: Fri, 19 Mar 2021 07:38:47 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

"Cook, Malcolm" <MEC@stowers.org> writes:

> Eric S Fraga <mailto:e.fraga@ucl.ac.uk> writes:
>>
>>> On Tuesday, 16 Mar 2021 at 09:56, Loris Bennett wrote:
>>>> How can I avoid having to declare the variable 'user' for both blocks?
>>>
>>> I imagine you could use a property, as in
>>>
>>> #+property: header-args :var user=loris
>>>
>>> or even make it specific for the particular language.
>>>
>>> (untested)
>>
>>Thanks for point out using 'header-args;' as property. However, if I do
>>the following, the variable is unset in the shell script:
>>
>>#+properties: header-args :var user=loris
>>
>>#+begin_src sh
>>echo user: ${user}
>>#+end_src
>>
>>#+RESULTS:
>>: user:
>>
>>Is that supposed to work, or am I doing something wrong?
>
> I am unfamiliar with using the plural form of property, as you are trying, at 
> buffer-level nor do I see  documented possible here:
> https://orgmode.org/manual/Property-Syntax.html#Property-Syntax
>
> try this:
>
> #+property: header-args:sh :var user="loris"
> #+begin_src sh
>
> echo user: ${user}
> #+end_src
>
> Important: After adding or modifying the #+property line, you will need to 
> instruct org to "refresh your local setup" which I typically accomplish by 
> positioning the point on that line and typing C-c C-c

This doesn't work for me - there is no error, but I get the same result
as above, i.e. the variable ${users} is not set.  Does it work for you?  

What does work for me is using a section property rather than a buffer
property: 

* Dummy Section
  :PROPERTIES:
  :header-args: :R :var user="loris"
  :END:

#+begin_src sh
  echo user: ${user}
#+end_src

#+RESULTS:
: user: loris

However, the restriction to source blocks of a particular language does
not seem to work like this, but maybe I have got the syntax wrong
(again).

>
>>
>>Cheers,
>>
>>Loris
>>
>>-- 
>>This signature is currently under construction.
>>



reply via email to

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