[Top][All Lists]

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

Re: [O] Using property values in source code blocks

From: Charles C. Berry
Subject: Re: [O] Using property values in source code blocks
Date: Sat, 16 Jul 2016 09:02:35 -0700
User-agent: Alpine 2.20 (OSX 67 2015-01-07)

On Fri, 15 Jul 2016, Joon Ro wrote:


--8<---------------cut here---------------start------------->8---

* Top Heading

#+NAME: get-property
#+BEGIN_SRC emacs-lisp :noweb yes :var prop="prop" :var pom=0
(car (org-entry-get-multivalued-property pom prop))

** Subheading
:DUMMY: 100

#+BEGIN_SRC shell :noweb yes
echo <<get-property(prop="DUMMY",pom=(point))>>

: 100

--8<---------------cut here---------------end--------------->8---

Hi Chuck,

Thank you so much. It definitely works when I evaluate the code block - but my ultimate goal is to tangle the source code (I want to generate bunch of script files with a template using property values), and when I tangle the code block it returns nil.

I do not see an easy way to do what you want only with tangle.

There are hooks you can define that might enable you to set things up. Maybe you can use `org-babel-pre-tangle-hook' to collect the property values and put them somewhere that `org-babel-post-tangle-hook' can get at them and use them to modify the tangled results accordingly. Or maybe `org-babel-post-tangle-hook' can do it by using methods like those in `org-babel-detangle' to look back at the *.org file.

Another alternative is to write all of your code blocks so they will execute to create the code you want as results and then tangle those results. You would use :wrap like this:

--8<---------------cut here---------------start------------->8---

#+BEGIN_SRC shell :noweb yes :wrap "src shell :tangle ./tangle-test.sh"
echo "echo " <<get-property(prop="DUMMY",pom=(point))>>

--8<---------------cut here---------------end--------------->8---

Execute the src block and then tangle the buffer.

In fact, if you go that route it might make more sense to write elisp code blocks to find the prpoerty values and then format the results.


reply via email to

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