From a833d35159fdc07b474fd66f31bb07e1768aeb87 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Tue, 23 Jun 2015 23:41:30 +0200 Subject: [PATCH] ox: Properly fix internal regexps after each buffer change * lisp/ox.el (org-export-as): Refresh regexps before executing Babel code, running last hook and parsing buffer so precomputed regular expressions are correct at each of these steps. This is not necessary before macros since those are not expected to rely on computed expression. Actually, advanced macros, i.e. with "(eval ...)" syntax, could make use of them, but a Babel snippet is more likely in this situation. Reported-by: Robert Klein --- lisp/ox.el | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index f60ff125b..020d5253e 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -2920,27 +2920,34 @@ Return code as a string." org-export-options-alist)))) tree) ;; Update communication channel and get parse tree. Buffer - ;; isn't parsed directly. Instead, a temporary copy is - ;; created, where include keywords, macros are expanded and - ;; code blocks are evaluated. + ;; isn't parsed directly. Instead, all buffer modifications + ;; and consequent parsing are undertaken in a temporary copy. (org-export-with-buffer-copy ;; 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. (org-export-expand-include-keyword) (org-export--delete-comments) - ;; Refresh buffer properties, radio targets and macros after - ;; including files. - (org-set-regexps-and-options) - (org-update-radio-target-regexp) (org-macro-initialize-templates) (org-macro-replace-all org-macro-templates nil 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) (org-export-execute-babel-code) + (org-set-regexps-and-options) + (org-update-radio-target-regexp) ;; Run last hook with current back-end's name as argument. + ;; Update buffer properties and radio targets one last time + ;; before parsing. (goto-char (point-min)) (save-excursion (run-hook-with-args 'org-export-before-parsing-hook (org-export-backend-name backend))) + (org-set-regexps-and-options) + (org-update-radio-target-regexp) ;; Update communication channel with environment. Also ;; install user's and developer's filters. (setq info -- 2.11.4.GIT