org-export: Expand include keywords before macros
* contrib/lisp/org-export.el (org-export-as): Expand include keywords before macros. This allows to specify macro templates in the included file. * testing/examples/macro-templates.org: New file for testing purposes. * testing/lisp/test-org-export.el: Add test.
This commit is contained in:
parent
bbdd81ad37
commit
89d6a26f8d
|
@ -2552,8 +2552,8 @@ Return code as a string."
|
||||||
(current-buffer))))
|
(current-buffer))))
|
||||||
(org-export-with-current-buffer-copy
|
(org-export-with-current-buffer-copy
|
||||||
(unless noexpand
|
(unless noexpand
|
||||||
(org-export-expand-macro info)
|
|
||||||
(org-export-expand-include-keyword)
|
(org-export-expand-include-keyword)
|
||||||
|
(org-export-expand-macro info)
|
||||||
;; TODO: Setting `org-current-export-file' is
|
;; TODO: Setting `org-current-export-file' is
|
||||||
;; required by Org Babel to properly resolve
|
;; required by Org Babel to properly resolve
|
||||||
;; noweb references. Once "org-exp.el" is
|
;; noweb references. Once "org-exp.el" is
|
||||||
|
@ -2724,6 +2724,9 @@ Point is at buffer's beginning when BODY is applied."
|
||||||
(defun org-export-expand-macro (info)
|
(defun org-export-expand-macro (info)
|
||||||
"Expand every macro in buffer.
|
"Expand every macro in buffer.
|
||||||
INFO is a plist containing export options and buffer properties."
|
INFO is a plist containing export options and buffer properties."
|
||||||
|
;; First update macro templates since #+INCLUDE keywords might have
|
||||||
|
;; added some new ones.
|
||||||
|
(org-macro-initialize-templates)
|
||||||
(org-macro-replace-all
|
(org-macro-replace-all
|
||||||
;; Before expanding macros, install {{{author}}}, {{{date}}},
|
;; Before expanding macros, install {{{author}}}, {{{date}}},
|
||||||
;; {{{email}}} and {{{title}}} templates.
|
;; {{{email}}} and {{{title}}} templates.
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Time-stamp: <2012-10-10 13:51:10 nicolas>
|
||||||
|
#+TITLE: Macro templates
|
||||||
|
#+MACRO: included-macro success
|
|
@ -436,7 +436,6 @@ body\n")))
|
||||||
(equal "#+MACRO: macro1 value\nvalue"
|
(equal "#+MACRO: macro1 value\nvalue"
|
||||||
(org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
|
(org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
|
||||||
(let (info)
|
(let (info)
|
||||||
(org-macro-initialize-templates)
|
|
||||||
(org-export-expand-macro info) (buffer-string)))))
|
(org-export-expand-macro info) (buffer-string)))))
|
||||||
;; Export specific macros.
|
;; Export specific macros.
|
||||||
(should
|
(should
|
||||||
|
@ -449,7 +448,18 @@ body\n")))
|
||||||
#+EMAIL: me@here
|
#+EMAIL: me@here
|
||||||
{{{author}}} {{{date}}} {{{email}}} {{{title}}}"
|
{{{author}}} {{{date}}} {{{email}}} {{{title}}}"
|
||||||
(let ((info (org-export-get-environment)))
|
(let ((info (org-export-get-environment)))
|
||||||
(org-macro-initialize-templates)
|
(org-export-expand-macro info)
|
||||||
|
(goto-char (point-max))
|
||||||
|
(buffer-substring (line-beginning-position)
|
||||||
|
(line-end-position))))))
|
||||||
|
;; Expand macros with templates in included files.
|
||||||
|
(should
|
||||||
|
(equal "success"
|
||||||
|
(org-test-with-temp-text
|
||||||
|
(format "#+INCLUDE: \"%s/examples/macro-templates.org\"
|
||||||
|
{{{included-macro}}}" org-test-dir)
|
||||||
|
(let (info)
|
||||||
|
(org-export-expand-include-keyword)
|
||||||
(org-export-expand-macro info)
|
(org-export-expand-macro info)
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(buffer-substring (line-beginning-position)
|
(buffer-substring (line-beginning-position)
|
||||||
|
|
Loading…
Reference in New Issue