浏览代码

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 <RoKlein@roklein.de>
<http://permalink.gmane.org/gmane.emacs.orgmode/98550>
Nicolas Goaziou 9 年之前
父节点
当前提交
a833d35159
共有 1 个文件被更改,包括 14 次插入7 次删除
  1. 14 7
      lisp/ox.el

+ 14 - 7
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