I often want to define a whole bunch of variables at the top of an org file. In some cases I think it would be really nice to define all the variables in a table. So far, the best solution I've come up with is this:
#+NAME: variables
| Variable | Value | Description |
|----------+------------+-------------|
| user1 | alice | Manager |
| user2 | bob | Developer |
#+NAME: lookup
#+begin_src emacs-lisp :var data=variables var="a var name"
(nth 1 (assoc var data))
#+end_src
#+begin_src sh :var user=lookup(var="user1")
echo $user
#+end_src
#+RESULTS:
: alice
That works, but the syntax :var user=lookup(var="user1")
is verbose, and it gets tiresome to call lookup
in every :var
header argument. I'm wondering if there is a way to register each variable and value in the table as though they were defined like this:
#+NAME: user1
: alice
#+NAME: user2
: bob
That way, you could write source blocks with simple and familiar
:var
header arguments, like:
#+begin_src sh :var user=user1
echo $user
#+end_src
#+RESULTS:
: alice
So I guess my question is: is there a way to "register" the variables/values in the variables
table in such a way that would let me use them like :var user=user1
?
Or even just an alternative way to do something similar that you find works for you?
EDIT: I perused the org source code a bit; I don't see any super easy way to do this. Maybe the best idea would be to introduce a new header argument, like #+begin_src :tblvar user=user1
, which resolves variables defined in a table.