org-element-cache: Fix indirect buffer tracking

* lisp/org-element.el (org-element--cache-setup-change-functions):
Make sure that indirect buffers are registered to be traversed in
`org-fold-core-cycle-over-indirect-buffers' in
`org-element--cache-active-p'.
`org-fold-core-decouple-indirect-buffer-folds' may not be called in
some scenarios when Org mode is active.

The reproducer that revealed the problem is in
https://orgmode.org/list/CAD6d+LUJ7St5_muvwqzE80EfHSoiMmZD+qDTAojeN0L7v+zsCQ@mail.gmail.com
This commit is contained in:
Ihor Radchenko 2024-06-05 14:32:50 +02:00
parent de0df5b925
commit ac1d58477a
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 5 additions and 0 deletions

View File

@ -7247,6 +7247,11 @@ that range. See `after-change-functions' for more information."
(when (buffer-base-buffer) (when (buffer-base-buffer)
(setq-local org-element--cache nil) (setq-local org-element--cache nil)
(setq-local org-element--headline-cache nil)) (setq-local org-element--headline-cache nil))
;; Register current buffer in `org-fold-core--indirect-buffers' to
;; be used within `org-fold-core-cycle-over-indirect-buffers'.
;; FIXME: We should eventually factor out indirect buffer tracking
;; from org-fold-core.
(org-fold-core-decouple-indirect-buffer-folds)
(add-hook 'before-change-functions (add-hook 'before-change-functions
#'org-element--cache-before-change nil t) #'org-element--cache-before-change nil t)
;; Run `org-element--cache-after-change' early to handle cases ;; Run `org-element--cache-after-change' early to handle cases