From c3c1c52eb8db75ed0691b0f5b21f24ee5b1f6077 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 11 Dec 2017 14:50:02 +0100 Subject: [PATCH] ox: Fix inline source block evaluation * lisp/ox.el (org-export-as): Specifically expand {{{results}}} macro after Babel code execution. * testing/lisp/test-ox.el (test-org-export/expand-macro): Add test. Reported-by: "Berry, Charles" --- lisp/ox.el | 12 ++++++++---- testing/lisp/test-ox.el | 10 +++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index 00aba6f8a..744e94159 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3034,20 +3034,24 @@ 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. + ;; 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 - ;; potentially invasive previous changes. Likewise, do it - ;; again after executing Babel code. (org-set-regexps-and-options) (org-update-radio-target-regexp) + ;; Possibly execute Babel code. Re-run a macro expansion + ;; specifically for {{{results}}} since inline source blocks + ;; may have generated some more. Refresh buffer properties + ;; and radio targets another time. (when org-export-use-babel (org-babel-exp-process-buffer) + (org-macro-replace-all '(("results" . "$1")) parsed-keywords) (org-set-regexps-and-options) (org-update-radio-target-regexp)) ;; Run last hook with current back-end's name as argument. diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index 25ef8a5c1..d9b96926b 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -1431,7 +1431,15 @@ Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote] ;; Throw an error when a macro definition is missing. (should-error (org-test-with-temp-text "{{{missing}}}" - (org-export-as (org-test-default-backend))))) + (org-export-as (org-test-default-backend)))) + ;; Inline source blocks generate {{{results}}} macros. Evaluate + ;; those. + (should + (equal "=2=\n" + (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))))))) (ert-deftest test-org-export/before-processing-hook () "Test `org-export-before-processing-hook'."