emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] `org-macro--collect-macros' can collect macro definitions from include files
@ 2014-02-05 16:09 Fabrice Niessen
  2014-02-05 16:17 ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Fabrice Niessen @ 2014-02-05 16:09 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello,

As the DOCSTRING of the function `org-macro--collect-macros' tells it,
it "collects macro definitions in current buffer and setup files", not
from INCLUDE files.

This patch ensures that the above does work.

From a8737be0b12ce700cd348c47f91694bfc0fbe7b8 Mon Sep 17 00:00:00 2001
From: "Fabrice Niessen" <fni-news-TA4HMoP+1wHrZ44/DZwexQ@public.gmane.org>
Date: Wed, 5 Feb 2014 16:59:58 +0100
Subject: [PATCH] Collect macro definitions from INCLUDE files as well

* org-macro.el (org-macro--collect-macros): INCLUDE files are looked up
when searching for macro definitions.

---
 lisp/org-macro.el |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lisp/org-macro.el b/lisp/org-macro.el
index 50ce438..7f438ed 100644
--- a/lisp/org-macro.el
+++ b/lisp/org-macro.el
@@ -78,7 +78,7 @@ Return an alist containing all macro templates found."
 	      (org-with-wide-buffer
 	       (goto-char (point-min))
 	       (while (re-search-forward
-		       "^[ \t]*#\\+\\(MACRO\\|SETUPFILE\\):" nil t)
+		       "^[ \t]*#\\+\\(MACRO\\|SETUPFILE\\|INCLUDE\\):" nil t)
 		 (let ((element (org-element-at-point)))
 		   (when (eq (org-element-type element) 'keyword)
 		     (let ((val (org-element-property :value element)))

-- 
Fabrice Niessen
Leuven, Belgium
http://www.pirilampo.org/

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

* Re: [PATCH] `org-macro--collect-macros' can collect macro definitions from include files
  2014-02-05 16:09 [PATCH] `org-macro--collect-macros' can collect macro definitions from include files Fabrice Niessen
@ 2014-02-05 16:17 ` Bastien
  2014-02-05 16:27   ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien @ 2014-02-05 16:17 UTC (permalink / raw)
  To: Fabrice Niessen; +Cc: public-emacs-orgmode-mXXj517/zsQ



"Fabrice Niessen" <fni-news-TA4HMoP+1wHrZ44/DZwexQ@public.gmane.org>
writes:

> As the DOCSTRING of the function `org-macro--collect-macros' tells it,
> it "collects macro definitions in current buffer and setup files", not
> from INCLUDE files.

Then your patch should change the docstring too.

I think we want to collect macros from setupfile only,
that's one of the differences between INCLUDE and SETUPFILE.

But I'll let Nicolas review and decide.

-- 
 Bastien

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

* Re: [PATCH] `org-macro--collect-macros' can collect macro definitions from include files
  2014-02-05 16:17 ` Bastien
@ 2014-02-05 16:27   ` Nicolas Goaziou
       [not found]     ` <8738jx34p1.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2014-02-05 16:27 UTC (permalink / raw)
  To: Bastien; +Cc: public-emacs-orgmode-mXXj517/zsQ, Fabrice Niessen



Hello,

Bastien <bzg@gnu.org> writes:

> "Fabrice Niessen" <fni-news-TA4HMoP+1wHrZ44/DZwexQ@public.gmane.org>
> writes:
>
>> As the DOCSTRING of the function `org-macro--collect-macros' tells it,
>> it "collects macro definitions in current buffer and setup files", not
>> from INCLUDE files.
>
> Then your patch should change the docstring too.
>
> I think we want to collect macros from setupfile only,
> that's one of the differences between INCLUDE and SETUPFILE.

I agree.

Not all "Include" files are Org files. Moreover, "INCLUDE" keywords are
expanded before initializing macro templates during export, so "MACRO"
keywords should be read when appropriate.


Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] `org-macro--collect-macros' can collect macro definitions from include files
       [not found]     ` <8738jx34p1.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-02-05 20:11       ` Fabrice Niessen
  0 siblings, 0 replies; 4+ messages in thread
From: Fabrice Niessen @ 2014-02-05 20:11 UTC (permalink / raw)
  To: Nicolas Goaziou
  Cc: Bastien, public-emacs-orgmode-mXXj517/zsQ-wOFGN7rlS/M9smdsby/KFg



Hello,

Nicolas Goaziou wrote:
> Bastien <bzg-mXXj517/zsQ@public.gmane.org> writes:
>> "Fabrice Niessen" writes:
>>
>>> As the DOCSTRING of the function `org-macro--collect-macros' tells it,
>>> it "collects macro definitions in current buffer and setup files", not
>>> from INCLUDE files.
>>
>> Then your patch should change the docstring too.

Right!

>> I think we want to collect macros from setupfile only,
>> that's one of the differences between INCLUDE and SETUPFILE.
>
> I agree.
>
> Not all "Include" files are Org files.

OK, but that shouldn't be a problem either: if there is no #+MACRO in an
"Include" file, that doesn't matter...

> Moreover, "INCLUDE" keywords are expanded before initializing macro
> templates during export, so "MACRO" keywords should be read when
> appropriate.

You say that the order of operations, during export, is:

- Include files through "INCLUDE" keywords
- Expand macros

OK. Still, I don't understand what you mean by "so MACRO keywords should
be read when appropriate"?

Anyway, let me explain what I wish such a feature (_or_ the opposite:
that Babel blocks are allowed in SETUPFILE)...

I'm sharing on GitHub a project [1] where I write Org macros that
everybody could once need, and these are easily accessible (once cloned)
in every file, after a simple directive such as:

  #+INCLUDE: /path/to/org-macros.setup

As I do have Babel code blocks inside the `org-macros.setup' file, it
needs to be loaded via the "INCLUDE" directive, not via a "SETUPFILE".

Example of such macro calling a Babel code block:

  ╭────
  │ #+name: version-history
  │ #+begin_src sh :exports none :results silent :colnames '(Version Date Author Comment)
  │ git log --pretty=format:"%h%x09%ad%x09%an%x09%s" --date=short | head -n 5
  │ #+end_src
  │
  │ #+MACRO: version-history call_version-history[:eval yes]()[:eval yes :results table :colnames '(Version Date Author Comment)]
  ╰────

So, thanks to the INCLUDE directive, I already have a one-liner to
include such "extended macros". But these aren't collected by
`org-macro--collect-macros'...

Best regards,
Fabrice

[1] https://github.com/fniessen/org-macros

-- 
Fabrice Niessen
Leuven, Belgium
http://www.pirilampo.org/

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

end of thread, other threads:[~2014-02-05 20:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-05 16:09 [PATCH] `org-macro--collect-macros' can collect macro definitions from include files Fabrice Niessen
2014-02-05 16:17 ` Bastien
2014-02-05 16:27   ` Nicolas Goaziou
     [not found]     ` <8738jx34p1.fsf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-02-05 20:11       ` Fabrice Niessen

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