emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Including file from a macro?
@ 2018-06-27  7:57 Diego Zamboni
  2018-06-27  8:01 ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Diego Zamboni @ 2018-06-27  7:57 UTC (permalink / raw)
  To: Org-mode

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

Hi,

Is it possible to use "#+include" from within a macro?

I have the following two files:

t1.org:
-----
#+MACRO: newline    (eval "\n")
#+MACRO: module-summary ** $1 {{{newline}}}{{{newline}}}#+include:
"./$1.org::file-summary"

{{{module-summary(t2)}}}
-----

t2.org:
-----
* t2 file

#+name: file-summary
This is the file summary
-----

This is another paragraph

If I export t1.org to org-mode, I get the following, which, if exported to
any other format (I have tested HTML and Markdown), correctly includes the
"file-summary" paragraph:

t1.org.org:
-----
# Created 2018-06-27 Wed 09:26
#+TITLE:
#+AUTHOR: Zamboni Diego
#+macro: newline    (eval "\n")
#+macro: module-summary ** $1 {{{newline}}}{{{newline}}}#+include:
"./$1.org::file-summary"

* t2

#+include: "./t2.org::file-summary"
-----

However, if I export t1.org directly to HTML or Markdown, I get only the
heading "* t2", but no included contents, as if the #+include line is not
being processed correctly.

Any ideas if this is possible?

Thanks,
--Diego

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

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

* Re: Including file from a macro?
  2018-06-27  7:57 Including file from a macro? Diego Zamboni
@ 2018-06-27  8:01 ` Nicolas Goaziou
  2018-06-27  9:28   ` Diego Zamboni
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2018-06-27  8:01 UTC (permalink / raw)
  To: Diego Zamboni; +Cc: Org-mode

Hello,

Diego Zamboni <diego@zzamboni.org> writes:

> Is it possible to use "#+include" from within a macro?

No, it isn't. Include keywords are expanded before macros.

Regards,

-- 
Nicolas Goaziou

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

* Re: Including file from a macro?
  2018-06-27  8:01 ` Nicolas Goaziou
@ 2018-06-27  9:28   ` Diego Zamboni
  2018-06-27 16:42     ` Berry, Charles
  0 siblings, 1 reply; 4+ messages in thread
From: Diego Zamboni @ 2018-06-27  9:28 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org-mode

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

Hi Nicolas,

(sorry for repeat- resending reply to list)

Thanks for the clarification. Do you think there could be a way to achieve
what I need (basically what was shown in my question). I would to build a
summary file with links and selected paragraphs from multiple other files
in the same directory (use case: I want to automate the creation of
README.org at https://github.com/zzamboni/elvish-modules/, among others). I
can do the headline/include by hand (or using YAsnippets maybe), but I
thought it would be much easier to just automate this with macros.

Thanks for any ideas.
--Diego


On Wed, Jun 27, 2018 at 10:01 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> Diego Zamboni <diego@zzamboni.org> writes:
>
> > Is it possible to use "#+include" from within a macro?
>
> No, it isn't. Include keywords are expanded before macros.
>
> Regards,
>
> --
> Nicolas Goaziou
>

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

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

* Re: Including file from a macro?
  2018-06-27  9:28   ` Diego Zamboni
@ 2018-06-27 16:42     ` Berry, Charles
  0 siblings, 0 replies; 4+ messages in thread
From: Berry, Charles @ 2018-06-27 16:42 UTC (permalink / raw)
  To: Diego Zamboni; +Cc: Org-mode, Nicolas Goaziou



> On Jun 27, 2018, at 2:28 AM, Diego Zamboni <diego@zzamboni.org> wrote:
> 
> Hi Nicolas,
> 
> (sorry for repeat- resending reply to list)
> 
> Thanks for the clarification. Do you think there could be a way to achieve what I need (basically what was shown in my question). I would to build a summary file with links and selected paragraphs from multiple other files in the same directory (use case: I want to automate the creation of README.org at https://github.com/zzamboni/elvish-modules/, among others). I can do the headline/include by hand (or using YAsnippets maybe), but I thought it would be much easier to just automate this with macros.
> 


You can do this:

#+MACRO: include (eval (org-export-string-as (concat "#+include: " $1 "\n") 'org t))

and then 

{{{include("myfile.org" :lines "1-10")}}}

will drop those lines into the file as the output of an export to `org'. You will need to customize export backends to include `org'. Or you can use some other backend if you put the macro call inside an export block.

However, the results may be surprising - macros defined in the main document will not function in the included document unless you also defined them there, babel code will run out of sync with babel in the main document, and so on.  I am not sure how this might affect internal hyperlinks, so try some cases if you need that to work before you commit to doing something like this.

So unless what you are doing inside the included document is pretty tame, it may not offer you all that you want.

HTH,

Chuck


> Thanks for any ideas.
> --Diego
> 
> 
> On Wed, Jun 27, 2018 at 10:01 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> Hello,
> 
> Diego Zamboni <diego@zzamboni.org> writes:
> 
> > Is it possible to use "#+include" from within a macro?
> 
> No, it isn't. Include keywords are expanded before macros.
> 
> Regards,
> 
> -- 
> Nicolas Goaziou
> 

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

end of thread, other threads:[~2018-06-27 16:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-27  7:57 Including file from a macro? Diego Zamboni
2018-06-27  8:01 ` Nicolas Goaziou
2018-06-27  9:28   ` Diego Zamboni
2018-06-27 16:42     ` Berry, Charles

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