branch: externals/org
commit 9c255cacfea64e2ef90892f2466cd3fc0c96f640
Author: Ihor Radchenko <[email protected]>
Commit: Ihor Radchenko <[email protected]>
org-element-ignored-local-variables: Add missing variables
This fixes ox-hugo bug when Org buffer copy cache is corrupted.
* lisp/org-element.el (org-element--cache-variables): Add
more state variables. Move above
`org-element-ignored-local-variables' definition.
(org-element-ignored-local-variables): Make use of the value of
`org-element--cache-variables'.
*
testing/lisp/test-org-element.el (test-org-element/cache-ignored-locals):
Add guard against adding new cache state variables that are not listed
in `org-element--cache-variables'.
Reported-by: George Kettleborough <[email protected]>
Link:
https://orgmode.org/list/[email protected]
---
lisp/org-element.el | 33 +++++++++++++++------------------
testing/lisp/test-org-element.el | 25 +++++++++++++++++++++++++
2 files changed, 40 insertions(+), 18 deletions(-)
diff --git a/lisp/org-element.el b/lisp/org-element.el
index fe747e0660..2ef4657ad3 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -499,14 +499,22 @@ past the brackets."
(goto-char end)
(buffer-substring-no-properties (1+ pos) (1- end)))))))))
+(defconst org-element--cache-variables
+ '( org-element--cache org-element--cache-size
+ org-element--headline-cache org-element--headline-cache-size
+ org-element--cache-hash-left org-element--cache-hash-right
+ org-element--cache-sync-requests org-element--cache-sync-timer
+ org-element--cache-sync-keys-value org-element--cache-change-tic
+ org-element--cache-last-buffer-size
+ org-element--cache-diagnostics-ring
+ org-element--cache-diagnostics-ring-size
+ org-element--cache-gapless
+ org-element--cache-change-warning)
+ "List of variable symbols holding cache state.")
+
(defconst org-element-ignored-local-variables
- '( org-font-lock-keywords org-element--cache-change-tic
- org-element--cache-change-tic org-element--cache-size
- org-element--headline-cache-size
- org-element--cache-sync-keys-value
- org-element--cache-change-warning org-element--headline-cache
- org-element--cache org-element--cache-sync-keys
- org-element--cache-sync-requests org-element--cache-sync-timer)
+ `( org-font-lock-keywords
+ ,@org-element--cache-variables)
"List of variables not copied through upon Org buffer duplication.
Export process and parsing in `org-element-parse-secondary-string'
takes place on a copy of the original buffer. When this copy is
@@ -5791,17 +5799,6 @@ See `org-element--cache-key' for more information.")
(defvar-local org-element--cache-last-buffer-size nil
"Last value of `buffer-size' for registered changes.")
-(defconst org-element--cache-variables
- '( org-element--cache org-element--cache-size
- org-element--headline-cache org-element--headline-cache-size
- org-element--cache-hash-left org-element--cache-hash-right
- org-element--cache-sync-requests org-element--cache-sync-timer
- org-element--cache-sync-keys-value org-element--cache-change-tic
- org-element--cache-last-buffer-size
- org-element--cache-gapless
- org-element--cache-change-warning)
- "List of variable symbols holding cache state.")
-
(defvar org-element--cache-non-modifying-commands
'(org-agenda
org-agenda-redo
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index ade255ea09..0098eaf152 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -5303,6 +5303,31 @@ a
:title
(org-element-lineage (org-element-at-point) '(headline))))))))
+(ert-deftest test-org-element/cache-ignored-locals ()
+ "Test `org-element-ignored-local-variables' value.
+Anything holding element cache state must not be copied around
+buffers, as in `org-element-copy-buffer' or
+`org-export-copy-buffer'. Otherwise, we may encounter
+hard-to-debug errors when cache state is either not up-to-date or
+modified by side effect, influencing the original values."
+ (mapatoms
+ (lambda (var)
+ (when (and (boundp var)
+ (symbol-value var)
+ (string-match-p "^org-element--cache" (symbol-name var))
+ (not (memq var '(org-element--cache-interrupt-C-g-max-count
+ org-element--cache-map-statistics-threshold
+ org-element--cache-variables
+ org-element--cache-interrupt-C-g-count
+ org-element--cache-interrupt-C-g
+ org-element--cache-element-properties
+ org-element--cache-sensitive-re
+ org-element--cache-hash-size
+ org-element--cache-non-modifying-commands
+ org-element--cache-self-verify-frequency
+ org-element--cache-diagnostics-level))))
+ (should (memq var org-element-ignored-local-variables))))))
+
(provide 'test-org-element)
;;; test-org-element.el ends here