소스 검색

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
Ihor Radchenko 3 년 전
부모
커밋
9f87b1cc33
1개의 변경된 파일15개의 추가작업 그리고 8개의 파일을 삭제
  1. 15 8
      lisp/org-element.el

+ 15 - 8
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)