org-export: Suppress cache persistence in buffer copies during export

* lisp/org-element.el (org-element-cache-reset): Add new optional
argument that suppresses all persistence-related calculations.
* lisp/org-table.el (org-element-cache-reset):
* lisp/org.el (org-element-cache-reset): Update function signature.
* lisp/ox.el (org-export--generate-copy-script): Do not try to use
cache persistence in throwaway buffer copies.

Reported-by: Rudolf Adamkovič <salutis@me.com>
Link: https://list.orgmode.org/m2zgef774u.fsf@me.com/T/#t
This commit is contained in:
Ihor Radchenko 2022-10-07 12:42:26 +08:00
parent 09fd5f886a
commit 514e3a9cd2
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
4 changed files with 8 additions and 6 deletions

View File

@ -7238,16 +7238,18 @@ Each element indicates the latest `org-element--cache-change-tic' when
change did not contain gaps.")
;;;###autoload
(defun org-element-cache-reset (&optional all)
(defun org-element-cache-reset (&optional all no-persistance)
"Reset cache in current buffer.
When optional argument ALL is non-nil, reset cache in all Org
buffers."
buffers.
When optional argument NO-PERSISTANCE is non-nil, do not try to update
the cache persistence in the buffer."
(interactive "P")
(dolist (buffer (if all (buffer-list) (list (current-buffer))))
(with-current-buffer (or (buffer-base-buffer buffer) buffer)
(when (and org-element-use-cache (derived-mode-p 'org-mode))
;; Only persist cache in file buffers.
(when (buffer-file-name)
(when (and (buffer-file-name) (not no-persistance))
(when (not org-element-cache-persistent)
(org-persist-unregister 'org-element--headline-cache (current-buffer))
(org-persist-unregister 'org-element--cache (current-buffer)))

View File

@ -59,7 +59,7 @@
(declare-function org-element-parse-buffer "org-element" (&optional granularity visible-only))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-type "org-element" (element))
(declare-function org-element-cache-reset "org-element" (&optional all))
(declare-function org-element-cache-reset "org-element" (&optional all no-persistence))
(declare-function org-entry-get "org" (pom property &optional inherit literal-nil))
(declare-function org-export-create-backend "ox" (&rest rest) t)
(declare-function org-export-data-with-backend "ox" (data backend info))

View File

@ -168,7 +168,7 @@ Stars are put in group 1 and the trimmed body in group 2.")
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
(declare-function org-element-at-point-no-context "org-element" (&optional pom))
(declare-function org-element-cache-refresh "org-element" (pos))
(declare-function org-element-cache-reset "org-element" (&optional all))
(declare-function org-element-cache-reset "org-element" (&optional all no-persistence))
(declare-function org-element-cache-map "org-element" (func &rest keys))
(declare-function org-element-contents "org-element" (element))
(declare-function org-element-context "org-element" (&optional element))

View File

@ -2671,7 +2671,7 @@ The function assumes BUFFER's major mode is `org-mode'."
(when str (erase-buffer) (insert str))
;; Make org-element-cache not complain about changed buffer
;; state.
(org-element-cache-reset)
(org-element-cache-reset nil 'no-persistence)
;; Narrowing.
(when narrowing
(apply #'narrow-to-region narrowing))