emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] Macro expansion in included files


From: Benny Simonsen
Subject: Re: [O] Macro expansion in included files
Date: Sat, 5 Mar 2011 10:12:24 +0100

2011/3/2 Benny Simonsen <address@hidden>:
> 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 @<strong>$1@</strong>
>
> {{{MacM(Main)}}}
>
> #+INCLUDE: "sub.org"
> = main.org END ========
>
> = sub.org START ========
> #+TITLE: Subpage
> #+MACRO: Mac @<strong>$1@</strong>
>
> {{{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)



reply via email to

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