emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Benny Simonsen <benny@slbs.dk>
To: emacs-orgmode@gnu.org
Subject: Re: Macro expansion in included files
Date: Sat, 5 Mar 2011 10:12:24 +0100	[thread overview]
Message-ID: <AANLkTi=mSHJnroNohvE2Vuf7pLNheXMm8Za0Lqh2iKBv@mail.gmail.com> (raw)
In-Reply-To: <AANLkTik75XGh_rCvd-NfiH=WaukT05=Hu+z3ay0iJe64@mail.gmail.com>

2011/3/2 Benny Simonsen <benny@slbs.dk>:
> 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)

  parent reply	other threads:[~2011-03-05  9:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-01 21:59 Macro expansion in included files Benny Simonsen
2011-03-02 16:26 ` Benny Simonsen
2011-03-03  9:10   ` Sébastien Vauban
2011-03-03 11:12     ` Benny Simonsen
2011-03-05  9:12   ` Benny Simonsen [this message]
2011-03-05 14:07     ` Sébastien Vauban
2011-03-05 17:55       ` Benny Simonsen
2011-06-30 16:29     ` Bastien
2011-08-30 17:22       ` Benny Simonsen
  -- strict thread matches above, loose matches on Subject: below --
2011-03-14 22:01 Benny Simonsen
2011-04-08 10:36 ` Carsten Dominik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTi=mSHJnroNohvE2Vuf7pLNheXMm8Za0Lqh2iKBv@mail.gmail.com' \
    --to=benny@slbs.dk \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).