summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-07-07 12:45:40 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-07-07 12:53:13 +0200
commit65ebb128bc380fe4795dedd655d6f7b685249842 (patch)
tree80e26770a7d7420cc667b314593666ae4e1bbdf8
parent623cc4625950f84442d4cde0faa9cc3ea0233283 (diff)
downloadorg-mode-65ebb128bc380fe4795dedd655d6f7b685249842.tar.gz
org-macro: Fix "results" macro
* lisp/org-macro.el (org-macro-initialize-templates): Do not initialize the special "results" macro. (org-macro-replace-all): Do not raise an error if "results" macro has no associated template yet. * lisp/ox.el (org-export-as): Update code comments. * testing/lisp/test-ox.el (test-org-export/expand-macro): Add test.
-rw-r--r--lisp/org-macro.el15
-rw-r--r--lisp/ox.el5
-rw-r--r--testing/lisp/test-ox.el11
3 files changed, 21 insertions, 10 deletions
diff --git a/lisp/org-macro.el b/lisp/org-macro.el
index 6e9a5cb..7c07e41 100644
--- a/lisp/org-macro.el
+++ b/lisp/org-macro.el
@@ -133,8 +133,8 @@ Templates are stored in buffer-local variable
In addition to buffer-defined macros, the function installs the
following ones: \"n\", \"author\", \"email\", \"keyword\",
-\"results\", \"time\", \"property\", and, if the buffer is
-associated to a file, \"input-file\" and \"modification-time\"."
+\"time\", \"property\", and, if the buffer is associated to
+a file, \"input-file\" and \"modification-time\"."
(org-macro--counter-initialize) ;for "n" macro
(setq org-macro-templates
(nconc
@@ -161,7 +161,6 @@ associated to a file, \"input-file\" and \"modification-time\"."
`("author" . ,(org-macro--find-keyword-value "AUTHOR"))
`("email" . ,(org-macro--find-keyword-value "EMAIL"))
'("keyword" . "(eval (org-macro--find-keyword-value $1))")
- '("results" . "$1")
'("time" . "(eval (format-time-string $1))")
`("title" . ,(org-macro--find-keyword-value "TITLE"))
'("property" . "(eval (org-macro--get-property $1 $2))")
@@ -240,7 +239,8 @@ a definition in TEMPLATES."
(goto-char (match-beginning 0))
(org-element-macro-parser))))))
(when macro
- (let* ((value (org-macro-expand macro templates))
+ (let* ((key (org-element-property :key macro))
+ (value (org-macro-expand macro templates))
(begin (org-element-property :begin macro))
(signature (list begin
macro
@@ -249,8 +249,7 @@ a definition in TEMPLATES."
;; macro with the same arguments is expanded at the
;; same position twice.
(cond ((member signature record)
- (error "Circular macro expansion: %s"
- (org-element-property :key macro)))
+ (error "Circular macro expansion: %s" key))
(value
(push signature record)
(delete-region
@@ -262,6 +261,10 @@ a definition in TEMPLATES."
;; Leave point before replacement in case of
;; recursive expansions.
(save-excursion (insert value)))
+ ;; Special "results" macro: if it is not defined,
+ ;; simply leave it as-is. It will be expanded in
+ ;; a second phase.
+ ((equal key "results"))
(t
(error "Undefined Org macro: %s; aborting"
(org-element-property :key macro))))))))))))
diff --git a/lisp/ox.el b/lisp/ox.el
index ac35ede..8f0a918 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -3043,15 +3043,14 @@ Return code as a string."
;; Run first hook with current back-end's name as argument.
(run-hook-with-args 'org-export-before-processing-hook
(org-export-backend-name backend))
- ;; Include files, delete comments and expand macros. Refresh
- ;; buffer properties and radio targets after these
- ;; potentially invasive changes.
(org-export-expand-include-keyword)
(org-export--delete-comment-trees)
(org-macro-initialize-templates)
(org-macro-replace-all (append org-macro-templates
org-export-global-macros)
parsed-keywords)
+ ;; Refresh buffer properties and radio targets after previous
+ ;; potentially invasive changes.
(org-set-regexps-and-options)
(org-update-radio-target-regexp)
;; Possibly execute Babel code. Re-run a macro expansion
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 1c429c8..245cb7e 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -1595,7 +1595,16 @@ Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
(org-test-with-temp-text "src_emacs-lisp{(+ 1 1)}"
(let ((org-export-use-babel t)
(org-babel-inline-result-wrap "=%s="))
- (org-export-as (org-test-default-backend)))))))
+ (org-export-as (org-test-default-backend))))))
+ ;; If inline source block is already associated to a "results"
+ ;; macro, do not duplicate it.
+ (should
+ (equal "src_emacs-lisp{(+ 1 1)} {{{results(=2=)}}}"
+ (org-test-with-temp-text "src_emacs-lisp{(+ 1 1)} {{{results(=2=)}}}"
+ (let ((org-export-use-babel t)
+ (org-babel-inline-result-wrap "=%s="))
+ (org-export-as (org-test-default-backend)))
+ (buffer-string)))))
(ert-deftest test-org-export/before-processing-hook ()
"Test `org-export-before-processing-hook'."