From ac1d58477ae6ce48fb6288137297f0d7b306e1dd Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Wed, 5 Jun 2024 14:32:50 +0200 Subject: [PATCH] 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 --- lisp/org-element.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lisp/org-element.el b/lisp/org-element.el index 7ce12352c..9f8e8df59 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -7247,6 +7247,11 @@ that range. See `after-change-functions' for more information." (when (buffer-base-buffer) (setq-local org-element--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 #'org-element--cache-before-change nil t) ;; Run `org-element--cache-after-change' early to handle cases