From mboxrd@z Thu Jan 1 00:00:00 1970 From: Benny Simonsen Subject: Re: Macro expansion in included files Date: Sat, 5 Mar 2011 10:12:24 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from [140.186.70.92] (port=40821 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PvnXL-0001Mr-Ho for emacs-orgmode@gnu.org; Sat, 05 Mar 2011 04:12:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PvnXG-0004MR-80 for emacs-orgmode@gnu.org; Sat, 05 Mar 2011 04:12:31 -0500 Received: from mail-vw0-f41.google.com ([209.85.212.41]:59706) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PvnXG-0004ME-3Q for emacs-orgmode@gnu.org; Sat, 05 Mar 2011 04:12:26 -0500 Received: by vws13 with SMTP id 13so3295389vws.0 for ; Sat, 05 Mar 2011 01:12:25 -0800 (PST) In-Reply-To: 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: emacs-orgmode@gnu.org 2011/3/2 Benny Simonsen : > Hi > > I would like to use macros in files that I include in another file. > The problem is that the macros don't expand in included files. Is > there something I have missed or? > > Example with two files, main.org and sub.org > > = main.org START ======== > #+TITLE: Mainpage > #+MACRO: MacM @$1@ > > {{{MacM(Main)}}} > > #+INCLUDE: "sub.org" > = main.org END ======== > > = sub.org START ======== > #+TITLE: Subpage > #+MACRO: Mac @$1@ > > {{{MacM(Sub)}}} > > {{{Mac(Sub)}}} > > * Subpage title > content > = sub.org END ======== > > I export to html e.g. via: > org-export-as-html-to-buffer on main.org > > The result is > {{{MacM(Main)}}} is expanded as expected but the {{{Mac*(Sub)}}} isn't expanded. > > Best regards > Benny > I have a patch that will expand macros in included files. Inclusion is performed before macro expansion If somebody includes files via MACRO then this will not work. Instead it is required to perform macro expansion, then inclusion and macro expansion again. This can still fail if somebody tries to include a page via an macro on a included page. BUT I have an (theoretical) issue: macros defined in included files (In this case the macro Mac that is defined in sub.org don't work in sub.org. ... This is not the way I normally work, I have a file containing my macros (loaded via SETUPFILE). If wanted, I can applly the patch by myself - if I have permissions. Best regards Benny --- Patch -------------------- diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 5f0ae5d..05e921a 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -1076,16 +1076,16 @@ on this string to produce the exported version." ;; Call the hook (run-hooks 'org-export-preprocess-hook) + ;; Handle include files, and call a hook + (org-export-handle-include-files-recurse) + (run-hooks 'org-export-preprocess-after-include-files-hook) + ;; Process the macros (org-export-preprocess-apply-macros) (run-hooks 'org-export-preprocess-after-macros-hook) (untabify (point-min) (point-max)) - ;; Handle include files, and call a hook - (org-export-handle-include-files-recurse) - (run-hooks 'org-export-preprocess-after-include-files-hook) - ;; Get rid of archived trees (org-export-remove-archived-trees archived-trees)