emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [PATCH] lisp/ob-screen.el: Support ~:var~ header args for babel bloc


From: Ken Mankoff
Subject: Re: [PATCH] lisp/ob-screen.el: Support ~:var~ header args for babel blocks
Date: Thu, 16 Mar 2023 00:12:26 -0400
User-agent: mu4e 1.8.13; emacs 27.1

Hi Ihor and Max,

Just a follow-up note that I am unlikely to be able to complete this patch 
anytime soon. Re-alignment of priorities because my need for :var header 
support in Org Babel is mitigated by a different method of injecting variables 
into Org Babel sections: Use noweb.

I find this more powerful than =:var=. The examples below show (1) setting a 
bash environment variable in screen, or (2) printing from a Python prompt after 
sshing to a remote computer. It is language agnostic. Because it uses 
PROPERTIES and not :var, it also lets me work in Org Column View mode.

* Header
:PROPERTIES:
:foo: 42
:END:

#+NAME: ex1-screen-bash
#+BEGIN_SRC screen
export foo="<<get_property("foo")>>"
#+END_SRC

#+NAME: ex2-ssh-python
#+BEGIN_SRC bash
ssh somewhere
python
print("<<get_property("foo")>>")
#+END_SRC

#+CALL: ex2-ssh-python()

#+RESULTS:
: foo


The relevant section from my library-of-babel is:

* Properties into header args
:PROPERTIES:
:hellomessage: hello
:END:

https://emacs.stackexchange.com/questions/41922/

#+NAME: get_property
#+BEGIN_SRC emacs-lisp :var prop_name="" :results silent
(org-with-point-at org-babel-current-src-block-location
  (org-entry-get nil prop_name t))
#+END_SRC

** Example Usage

*** Header arg

#+HEADER: :var prop_message=(org-entry-get nil "hellomessage" t)
#+BEGIN_SRC emacs-lisp
  (message prop_message)
#+END_SRC

#+RESULTS:
: hello

*** Noweb
#+BEGIN_SRC emacs-lisp :noweb yes
  (message "<<get_property("hellomessage")>>")
#+END_SRC

#+RESULTS:
: hello

#+BEGIN_SRC bash :noweb yes :results verbatim
echo "<<get_property("hellomessage")>>"
#+END_SRC

#+RESULTS:
: hello

If hope this helps someone if they need it.

  -k.



reply via email to

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