From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: [Babel] tangle - kind of macro expansion inside src blocks? Date: Mon, 14 Mar 2011 09:35:07 -0600 Message-ID: <87y64hyatw.fsf@gmail.com> References: <4D7E2683.9040208@gmx.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=45675 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pz9nh-00079K-RE for emacs-orgmode@gnu.org; Mon, 14 Mar 2011 11:35:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pz9ng-0006oe-3E for emacs-orgmode@gnu.org; Mon, 14 Mar 2011 11:35:17 -0400 Received: from mail-qw0-f41.google.com ([209.85.216.41]:43274) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pz9ng-0006oW-0s for emacs-orgmode@gnu.org; Mon, 14 Mar 2011 11:35:16 -0400 Received: by qwa26 with SMTP id 26so1756074qwa.0 for ; Mon, 14 Mar 2011 08:35:14 -0700 (PDT) In-Reply-To: <4D7E2683.9040208@gmx.net> (Olaf Hamann's message of "Mon, 14 Mar 2011 15:30:27 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: "Olaf.Hamann" Cc: emacs-orgmode@gnu.org 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" 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