emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Macro expansion in included files
@ 2011-03-01 21:59 Benny Simonsen
  2011-03-02 16:26 ` Benny Simonsen
  0 siblings, 1 reply; 11+ messages in thread
From: Benny Simonsen @ 2011-03-01 21:59 UTC (permalink / raw)
  To: emacs-orgmode

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
main.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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Macro expansion in included files
  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-05  9:12   ` Benny Simonsen
  0 siblings, 2 replies; 11+ messages in thread
From: Benny Simonsen @ 2011-03-02 16:26 UTC (permalink / raw)
  To: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Macro expansion in included files
  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
  1 sibling, 1 reply; 11+ messages in thread
From: Sébastien Vauban @ 2011-03-03  9:10 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Benny,

Benny Simonsen wrote:
> The result is {{{MacM(Main)}}} is expanded as expected but the
> {{{Mac*(Sub)}}} isn't expanded.

What's Mac*?

In your example, you just have MacM and Mac...

Best regards,
  Seb

-- 
Sébastien Vauban


--
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Macro expansion in included files
  2011-03-03  9:10   ` Sébastien Vauban
@ 2011-03-03 11:12     ` Benny Simonsen
  0 siblings, 0 replies; 11+ messages in thread
From: Benny Simonsen @ 2011-03-03 11:12 UTC (permalink / raw)
  To: emacs-orgmode

2011/3/3 Sébastien Vauban <wxhgmqzgwmuf@spammotel.com>:
> Hi Benny,
>
> Benny Simonsen wrote:
>> The result is {{{MacM(Main)}}} is expanded as expected but the
>> {{{Mac*(Sub)}}} isn't expanded.
>
> What's Mac*?
>
> In your example, you just have MacM and Mac...

MacM is the macro defined in main.org:
#+MACRO: MacM @<strong>$1@</strong>

and Mac is a similar macro in sub.org - just to see if it gives any
difference in sub.org about the macro is defined in the same file or
in another file.

The content of the two files should be visible in my original post(s).
If not let me hear.

- sorry I posted twice, but I couldn't see the fist message that I
have sent because of the filtering on gmail.


Best regards,
Benny

--
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Macro expansion in included files
  2011-03-02 16:26 ` Benny Simonsen
  2011-03-03  9:10   ` Sébastien Vauban
@ 2011-03-05  9:12   ` Benny Simonsen
  2011-03-05 14:07     ` Sébastien Vauban
  2011-06-30 16:29     ` Bastien
  1 sibling, 2 replies; 11+ messages in thread
From: Benny Simonsen @ 2011-03-05  9:12 UTC (permalink / raw)
  To: emacs-orgmode

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)

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: Macro expansion in included files
  2011-03-05  9:12   ` Benny Simonsen
@ 2011-03-05 14:07     ` Sébastien Vauban
  2011-03-05 17:55       ` Benny Simonsen
  2011-06-30 16:29     ` Bastien
  1 sibling, 1 reply; 11+ messages in thread
From: Sébastien Vauban @ 2011-03-05 14:07 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Benny,

Benny Simonsen wrote:
> 2011/3/2 Benny Simonsen <benny-krXKKDdbxn8@public.gmane.org>:
>> 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.

Your example looks wrong to me: you say Mac* is not working, but only MacM and
Mac are defined. What about the trailing the star?

Best regards,
  Seb

-- 
Sébastien Vauban

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Macro expansion in included files
  2011-03-05 14:07     ` Sébastien Vauban
@ 2011-03-05 17:55       ` Benny Simonsen
  0 siblings, 0 replies; 11+ messages in thread
From: Benny Simonsen @ 2011-03-05 17:55 UTC (permalink / raw)
  To: Sébastien Vauban; +Cc: emacs-orgmode

2011/3/5 Sébastien Vauban <wxhgmqzgwmuf@spammotel.com>:
> Hi Benny,
>
> Benny Simonsen wrote:
>> 2011/3/2 Benny Simonsen <benny@slbs.dk>:
>>> 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.
>
> Your example looks wrong to me: you say Mac* is not working, but only MacM and
> Mac are defined. What about the trailing the star?
>

The * was just a wildcard so Mac* means MacM and Mac.

A brief summary
MacM is defined in main.org - and expands in this file.
Mac is defined in sub.org - but neither MacM or Mac works in sub.org.

With my patch MacM works in both files, but Mac don't work - not a
problem for me - but not nice.

Best regards
Benny

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Macro expansion in included files
@ 2011-03-14 22:01 Benny Simonsen
  2011-04-08 10:36 ` Carsten Dominik
  0 siblings, 1 reply; 11+ messages in thread
From: Benny Simonsen @ 2011-03-14 22:01 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 942 bytes --]

Hi

Some time ago I was posting about a problem with macros in included
files - they will not expand.

Example with two files top.org and sub.org: macro in the included file
sub.org isn't expanded during export.
See the content of the example files below.

The patch fixes this so that the macro is expanded in both top.org and sub.org.

Setup:
org-mode: git master (head)
export top.org with org-export-as-html

I hope that the patch format is ok ("git diff" output) attached.

Best regards
Benny Simonsen

### top.org ############################################################
#+TITLE: Debug org file
#+MACRO: testmacro Expanded

{{{testmacro}}}

#+INCLUDE: "sub.org"
########################################################################

### sub.org ############################################################
#+TITLE: Included debug org file

{{{testmacro}}}
########################################################################

[-- Attachment #2: macro-expansion-in-included-files.patch --]
[-- Type: text/x-patch, Size: 565 bytes --]

diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index 34f101d..d6b23a9 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -1083,6 +1083,10 @@ 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)

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: Macro expansion in included files
  2011-03-14 22:01 Benny Simonsen
@ 2011-04-08 10:36 ` Carsten Dominik
  0 siblings, 0 replies; 11+ messages in thread
From: Carsten Dominik @ 2011-04-08 10:36 UTC (permalink / raw)
  To: Benny Simonsen; +Cc: emacs-orgmode

Applied, thanks.

- Carsten

On Mar 14, 2011, at 11:01 PM, Benny Simonsen wrote:

> Hi
> 
> Some time ago I was posting about a problem with macros in included
> files - they will not expand.
> 
> Example with two files top.org and sub.org: macro in the included file
> sub.org isn't expanded during export.
> See the content of the example files below.
> 
> The patch fixes this so that the macro is expanded in both top.org and sub.org.
> 
> Setup:
> org-mode: git master (head)
> export top.org with org-export-as-html
> 
> I hope that the patch format is ok ("git diff" output) attached.
> 
> Best regards
> Benny Simonsen
> 
> ### top.org ############################################################
> #+TITLE: Debug org file
> #+MACRO: testmacro Expanded
> 
> {{{testmacro}}}
> 
> #+INCLUDE: "sub.org"
> ########################################################################
> 
> ### sub.org ############################################################
> #+TITLE: Included debug org file
> 
> {{{testmacro}}}
> ########################################################################
> <macro-expansion-in-included-files.patch>

- Carsten

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Macro expansion in included files
  2011-03-05  9:12   ` Benny Simonsen
  2011-03-05 14:07     ` Sébastien Vauban
@ 2011-06-30 16:29     ` Bastien
  2011-08-30 17:22       ` Benny Simonsen
  1 sibling, 1 reply; 11+ messages in thread
From: Bastien @ 2011-06-30 16:29 UTC (permalink / raw)
  To: Benny Simonsen; +Cc: emacs-orgmode

Hi Benny,

Benny Simonsen <benny@slbs.dk> writes:

> I have a patch that will expand macros in included files.
> Inclusion is performed before macro expansion

Thanks for this patch, it looks good to me. 

Can someone test it and report any problems?  

Thanks!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Macro expansion in included files
  2011-06-30 16:29     ` Bastien
@ 2011-08-30 17:22       ` Benny Simonsen
  0 siblings, 0 replies; 11+ messages in thread
From: Benny Simonsen @ 2011-08-30 17:22 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 814 bytes --]

Hi

Now I have updated to head - It works, but I was a bit confused that the Mac
macro didn't expand ... forgot to read my old post :)

> 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).

Sorry for the late response.

Bastian:
Thank you for apllying the patch.

Cheers,
Benny

2011/6/30 Bastien <bzg@altern.org>

> Hi Benny,
>
> Benny Simonsen <benny@slbs.dk> writes:
>
> > I have a patch that will expand macros in included files.
> > Inclusion is performed before macro expansion
>
> Thanks for this patch, it looks good to me.
>
> Can someone test it and report any problems?
>
> Thanks!
>
> --
>  Bastien
>

[-- Attachment #2: Type: text/html, Size: 1404 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-08-30 17:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).