[O] [PATCH] `org-macro--collect-macros' can collect macro definitions from include files
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-n...@pirilampo.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/
Re: [O] [PATCH] `org-macro--collect-macros' can collect macro definitions from include files
Fabrice Niessen fni-news-TA4HMoP+1wHrZ44/dzw...@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
Re: [O] [PATCH] `org-macro--collect-macros' can collect macro definitions from include files
Hello, Bastien b...@gnu.org writes: Fabrice Niessen fni-news-TA4HMoP+1wHrZ44/dzw...@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
Re: [O] [PATCH] `org-macro--collect-macros' can collect macro definitions from include files
Hello, Nicolas Goaziou wrote: Bastien b...@gnu.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/