* [Babel] tangle - kind of macro expansion inside src blocks?
@ 2011-03-14 14:30 Olaf.Hamann
2011-03-14 15:35 ` Eric Schulte
0 siblings, 1 reply; 3+ messages in thread
From: Olaf.Hamann @ 2011-03-14 14:30 UTC (permalink / raw)
To: emacs-orgmode
Hello all,
is there a way to do so or are there plans to integrate
a macro expansion mechanism into org-babel-tangle
like that one org-mode already provides?
#+MACRO: name replacement
{{{name}}}
I would like to replace config parameter in begin_src...end_src blocks.
Change at one place in org-file shall change values in tangled code-files.
I helped myself with an ugly hack in org-babel-tangle,
so that following lines work for me at the moment.
#+MACRO CONFIG_PARAM01 45
#+begin_src sh :tangle file1.sh
echo org-mode set CONFIG_PARAMETER to: {{{CONFIG_PARAM01}}}
#+end_src
#+begin_src sh :tangle file2.sh
echo org-mode set CONFIG_PARAMETER to: {{{CONFIG_PARAM01}}}
#+end_src
(this is an example only - the language which I tangle to is not good at
local vars support,
so using $CONFIG_PARAMETER inside tangled code is no solution to me)
But this is no solution, so I ask whether there is already some
functionality to do like this,
which will nicely fit into the aspects of different languages to be used
in src blocks.
Work of org-babel-detangle will be harder when using such a macro
functionality
(supported languages need inline comments, what to do with other? ).
Regards,
Olaf
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Babel] tangle - kind of macro expansion inside src blocks?
2011-03-14 14:30 [Babel] tangle - kind of macro expansion inside src blocks? Olaf.Hamann
@ 2011-03-14 15:35 ` Eric Schulte
2011-03-14 18:06 ` Olaf.Hamann
0 siblings, 1 reply; 3+ messages in thread
From: Eric Schulte @ 2011-03-14 15:35 UTC (permalink / raw)
To: Olaf.Hamann; +Cc: emacs-orgmode
Hello Olaf,
I've just added a new hook through which you will be able to expand
regular Org-mode style macros in code block bodies during export. The
following org-mode snippet demonstrates its use.
First, add macro expansion to the new `org-babel-tangle-body-hook'.
#+begin_src emacs-lisp :results silent
(add-hook 'org-babel-tangle-body-hook
(lambda () (org-export-preprocess-apply-macros)))
#+end_src
Then define the macro. Note: you may need to export the buffer before
tangling so that the macro definition is noticed and processed by
Org-mode.
#+MACRO: CONFIG_PARAM01 45
Then on both export and tangling the macro in the following code block
will be replaced.
#+begin_src sh :tangle yes
echo org-mode set CONFIG_PARAMETER to: {{{CONFIG_PARAM01}}}
#+end_src
Cheers -- Eric
"Olaf.Hamann" <O.Hamann@gmx.net> writes:
> Hello all,
>
> is there a way to do so or are there plans to integrate
> a macro expansion mechanism into org-babel-tangle
> like that one org-mode already provides?
>
> #+MACRO: name replacement
> {{{name}}}
>
>
> I would like to replace config parameter in begin_src...end_src blocks.
> Change at one place in org-file shall change values in tangled code-files.
>
> I helped myself with an ugly hack in org-babel-tangle,
> so that following lines work for me at the moment.
>
> #+MACRO CONFIG_PARAM01 45
>
> #+begin_src sh :tangle file1.sh
> echo org-mode set CONFIG_PARAMETER to: {{{CONFIG_PARAM01}}}
> #+end_src
> #+begin_src sh :tangle file2.sh
> echo org-mode set CONFIG_PARAMETER to: {{{CONFIG_PARAM01}}}
> #+end_src
>
> (this is an example only - the language which I tangle to is not good at
> local vars support,
> so using $CONFIG_PARAMETER inside tangled code is no solution to me)
>
> But this is no solution, so I ask whether there is already some
> functionality to do like this,
> which will nicely fit into the aspects of different languages to be used
> in src blocks.
> Work of org-babel-detangle will be harder when using such a macro
> functionality
> (supported languages need inline comments, what to do with other? ).
>
> Regards,
> Olaf
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Babel] tangle - kind of macro expansion inside src blocks?
2011-03-14 15:35 ` Eric Schulte
@ 2011-03-14 18:06 ` Olaf.Hamann
0 siblings, 0 replies; 3+ messages in thread
From: Olaf.Hamann @ 2011-03-14 18:06 UTC (permalink / raw)
To: Eric Schulte; +Cc: Emacs-orgmode mailing list
Hi Eric,
thank you very much, it works as announced.
I have probs with replacing/overlaying the built-in org-mode in my Emacs
(w32-binary),
but that's not issue here.
After an eval-buffer of ob-tangle.el I can reproduce the expected result.
Exporting the buffer first is necessary, but that could be done by the
pre-tangle-hook I hope.
Thank you very much for that quick feature patch.
Regards,
Olaf
Am 14.03.2011 16:35, schrieb Eric Schulte:
> Hello Olaf,
>
> I've just added a new hook through which you will be able to expand
> regular Org-mode style macros in code block bodies during export. The
> following org-mode snippet demonstrates its use.
>
> First, add macro expansion to the new `org-babel-tangle-body-hook'.
>
> #+begin_src emacs-lisp :results silent
> (add-hook 'org-babel-tangle-body-hook
> (lambda () (org-export-preprocess-apply-macros)))
> #+end_src
>
> Then define the macro. Note: you may need to export the buffer before
> tangling so that the macro definition is noticed and processed by
> Org-mode.
>
> #+MACRO: CONFIG_PARAM01 45
>
> Then on both export and tangling the macro in the following code block
> will be replaced.
>
> #+begin_src sh :tangle yes
> echo org-mode set CONFIG_PARAMETER to: {{{CONFIG_PARAM01}}}
> #+end_src
>
> Cheers -- Eric
>
> "Olaf.Hamann"<O.Hamann@gmx.net> writes:
>
>> Hello all,
>>
>> is there a way to do so or are there plans to integrate
>> a macro expansion mechanism into org-babel-tangle
>> like that one org-mode already provides?
>>
>> #+MACRO: name replacement
>> {{{name}}}
>>
>>
>> I would like to replace config parameter in begin_src...end_src blocks.
>> Change at one place in org-file shall change values in tangled code-files.
>>
>> I helped myself with an ugly hack in org-babel-tangle,
>> so that following lines work for me at the moment.
>>
>> #+MACRO CONFIG_PARAM01 45
>>
>> #+begin_src sh :tangle file1.sh
>> echo org-mode set CONFIG_PARAMETER to: {{{CONFIG_PARAM01}}}
>> #+end_src
>> #+begin_src sh :tangle file2.sh
>> echo org-mode set CONFIG_PARAMETER to: {{{CONFIG_PARAM01}}}
>> #+end_src
>>
>> (this is an example only - the language which I tangle to is not good at
>> local vars support,
>> so using $CONFIG_PARAMETER inside tangled code is no solution to me)
>>
>> But this is no solution, so I ask whether there is already some
>> functionality to do like this,
>> which will nicely fit into the aspects of different languages to be used
>> in src blocks.
>> Work of org-babel-detangle will be harder when using such a macro
>> functionality
>> (supported languages need inline comments, what to do with other? ).
>>
>> Regards,
>> Olaf
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-03-14 18:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-14 14:30 [Babel] tangle - kind of macro expansion inside src blocks? Olaf.Hamann
2011-03-14 15:35 ` Eric Schulte
2011-03-14 18:06 ` Olaf.Hamann
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).