summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-10-10 11:52:54 (GMT)
committer Nicolas Goaziou <n.goaziou@gmail.com>2012-10-10 11:52:54 (GMT)
commit89d6a26f8d2fea3c8c7116b1196ae48bc93d5e16 (patch)
tree8e482ca2ad1723adff7a62e49534fffb952372af
parentbbdd81ad37b6f9b1853260afcdd1fd915a700a53 (diff)
downloadorg-mode-89d6a26f8d2fea3c8c7116b1196ae48bc93d5e16.zip
org-mode-89d6a26f8d2fea3c8c7116b1196ae48bc93d5e16.tar.gz
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.
-rw-r--r--contrib/lisp/org-export.el5
-rw-r--r--testing/examples/macro-templates.org3
-rw-r--r--testing/lisp/test-org-export.el14
3 files changed, 19 insertions, 3 deletions
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el
index 7113210..8315a97 100644
--- a/contrib/lisp/org-export.el
+++ b/contrib/lisp/org-export.el
@@ -2552,8 +2552,8 @@ Return code as a string."
(current-buffer))))
(org-export-with-current-buffer-copy
(unless noexpand
- (org-export-expand-macro info)
(org-export-expand-include-keyword)
+ (org-export-expand-macro info)
;; TODO: Setting `org-current-export-file' is
;; required by Org Babel to properly resolve
;; 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)
"Expand every macro in buffer.
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
;; Before expanding macros, install {{{author}}}, {{{date}}},
;; {{{email}}} and {{{title}}} templates.
diff --git a/testing/examples/macro-templates.org b/testing/examples/macro-templates.org
new file mode 100644
index 0000000..1c58691
--- a/dev/null
+++ b/testing/examples/macro-templates.org
@@ -0,0 +1,3 @@
+# Time-stamp: <2012-10-10 13:51:10 nicolas>
+#+TITLE: Macro templates
+#+MACRO: included-macro success
diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el
index b8463fb..e3b9af0 100644
--- a/testing/lisp/test-org-export.el
+++ b/testing/lisp/test-org-export.el
@@ -436,7 +436,6 @@ body\n")))
(equal "#+MACRO: macro1 value\nvalue"
(org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
(let (info)
- (org-macro-initialize-templates)
(org-export-expand-macro info) (buffer-string)))))
;; Export specific macros.
(should
@@ -449,7 +448,18 @@ body\n")))
#+EMAIL: me@here
{{{author}}} {{{date}}} {{{email}}} {{{title}}}"
(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)
(goto-char (point-max))
(buffer-substring (line-beginning-position)