From 9f87b1cc33962510d5169213c0ac7c40d5916631 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Fri, 29 Oct 2021 22:23:18 +0800 Subject: [PATCH] org-element.el: Handle cache requests inside `combine-change-calls' * lisp/org-element.el (org-element--cache-active-p): Prevent cache queries when `org-element--cache-after-change' is not in `after-change-functions'. `after-change-functions' can be temporalily set to nil by i.e. `combine-change-calls'. We should not try to get information from cache in such scenarios because cache may not yet be up-to-date. The modifications will only be registered upon exiting the `combine-change-calls' macro. Fixes https://list.orgmode.org/875ytggcuk.fsf@yandex.com/T/#t --- lisp/org-element.el | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 64aa26364..da08a5690 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -5600,15 +5600,22 @@ This function assumes `org-element--headline-cache' is a valid AVL tree." (and org-element-use-cache org-element--cache (derived-mode-p 'org-mode) - ;; org-num-mode calls some Org structure analysis functions - ;; that can trigger cache update in the middle of changes. See - ;; `org-num--verify' calling `org-num--skip-value' calling - ;; `org-entry-get' that uses cache. - ;; Forcefully disable cache when called from inside a - ;; modification hook, where `inhibit-modification-hooks' is set - ;; to t. (or called-from-cache-change-func-p - (not inhibit-modification-hooks) + (and + ;; org-num-mode calls some Org structure analysis functions + ;; that can trigger cache update in the middle of changes. See + ;; `org-num--verify' calling `org-num--skip-value' calling + ;; `org-entry-get' that uses cache. + ;; Forcefully disable cache when called from inside a + ;; modification hook, where `inhibit-modification-hooks' is set + ;; to t. + (not inhibit-modification-hooks) + ;; `combine-change-calls' sets `after-change-functions' to + ;; nil. We need not to use cache inside + ;; `combine-change-calls' because the buffer is potentially + ;; changed without notice (the change will be registered + ;; after exiting the `combine-change-calls' body though). + (memq #'org-element--cache-after-change after-change-functions)) (eq org-element--cache-change-tic (buffer-chars-modified-tick))))) (defun org-element--cache-find (pos &optional side)