org-export-as: Do not update buffer settings when not modified

* lisp/ox.el (org-export-as): Use `buffer-chars-modified-tick' and
avoid extra invocations of `org-set-regexps-and-options' and
`org-update-radio-target-regexp' when the buffer is not changed.
Also, disable folding checks.  Folding is irrelevant inside export
buffer.
This commit is contained in:
Ihor Radchenko 2022-06-16 01:03:18 +08:00
parent aa789b89d7
commit 076dd92acc
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 135 additions and 128 deletions

View File

@ -2938,6 +2938,7 @@ still inferior to file-local settings.
Return code as a string." Return code as a string."
(when (symbolp backend) (setq backend (org-export-get-backend backend))) (when (symbolp backend) (setq backend (org-export-get-backend backend)))
(org-export-barf-if-invalid-backend backend) (org-export-barf-if-invalid-backend backend)
(org-fold-core-ignore-modifications
(save-excursion (save-excursion
(save-restriction (save-restriction
;; Narrow buffer to an appropriate region or subtree for ;; Narrow buffer to an appropriate region or subtree for
@ -2962,11 +2963,12 @@ Return code as a string."
(mapcar (lambda (o) (and (eq (nth 4 o) 'parse) (nth 1 o))) (mapcar (lambda (o) (and (eq (nth 4 o) 'parse) (nth 1 o)))
(append (org-export-get-all-options backend) (append (org-export-get-all-options backend)
org-export-options-alist)))) org-export-options-alist))))
tree) tree modified-tick)
;; Update communication channel and get parse tree. Buffer ;; Update communication channel and get parse tree. Buffer
;; isn't parsed directly. Instead, all buffer modifications ;; isn't parsed directly. Instead, all buffer modifications
;; and consequent parsing are undertaken in a temporary copy. ;; and consequent parsing are undertaken in a temporary copy.
(org-export-with-buffer-copy (org-export-with-buffer-copy
(font-lock-mode -1)
;; Run first hook with current back-end's name as argument. ;; Run first hook with current back-end's name as argument.
(run-hook-with-args 'org-export-before-processing-hook (run-hook-with-args 'org-export-before-processing-hook
(org-export-backend-name backend)) (org-export-backend-name backend))
@ -2978,6 +2980,7 @@ Return code as a string."
;; potentially invasive changes. ;; potentially invasive changes.
(org-set-regexps-and-options) (org-set-regexps-and-options)
(org-update-radio-target-regexp) (org-update-radio-target-regexp)
(setq modified-tick (buffer-chars-modified-tick))
;; Possibly execute Babel code. Re-run a macro expansion ;; Possibly execute Babel code. Re-run a macro expansion
;; specifically for {{{results}}} since inline source blocks ;; specifically for {{{results}}} since inline source blocks
;; may have generated some more. Refresh buffer properties ;; may have generated some more. Refresh buffer properties
@ -2985,8 +2988,10 @@ Return code as a string."
(when org-export-use-babel (when org-export-use-babel
(org-babel-exp-process-buffer) (org-babel-exp-process-buffer)
(org-macro-replace-all '(("results" . "$1")) parsed-keywords) (org-macro-replace-all '(("results" . "$1")) parsed-keywords)
(unless (eq modified-tick (buffer-chars-modified-tick))
(org-set-regexps-and-options) (org-set-regexps-and-options)
(org-update-radio-target-regexp)) (org-update-radio-target-regexp))
(setq modified-tick (buffer-chars-modified-tick)))
;; Run last hook with current back-end's name as argument. ;; Run last hook with current back-end's name as argument.
;; Update buffer properties and radio targets one last time ;; Update buffer properties and radio targets one last time
;; before parsing. ;; before parsing.
@ -2994,8 +2999,10 @@ Return code as a string."
(save-excursion (save-excursion
(run-hook-with-args 'org-export-before-parsing-hook (run-hook-with-args 'org-export-before-parsing-hook
(org-export-backend-name backend))) (org-export-backend-name backend)))
(unless (eq modified-tick (buffer-chars-modified-tick))
(org-set-regexps-and-options) (org-set-regexps-and-options)
(org-update-radio-target-regexp) (org-update-radio-target-regexp))
(setq modified-tick (buffer-chars-modified-tick))
;; Update communication channel with environment. ;; Update communication channel with environment.
(setq info (setq info
(org-combine-plists (org-combine-plists
@ -3066,7 +3073,7 @@ Return code as a string."
(org-no-properties (org-no-properties
(org-export-filter-apply-functions (org-export-filter-apply-functions
(plist-get info :filter-final-output) (plist-get info :filter-final-output)
output info)))))))) output info)))))))))
;;;###autoload ;;;###autoload
(defun org-export-string-as (string backend &optional body-only ext-plist) (defun org-export-string-as (string backend &optional body-only ext-plist)