org-element-cache: Reduce memory footprint in indirect buffers

* lisp/org-element.el (org-element--cache-setup-change-functions): Set
buffer-local cache values to nil in indirect buffers.

Reported-by: Sebastian Wålinder <s.walinder@gmail.com>
Link: https://orgmode.org/list/87v8funovi.fsf@localhost
This commit is contained in:
Ihor Radchenko 2023-06-13 13:07:35 +03:00
parent 34082ff184
commit 2f7b35ac89
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 5 additions and 0 deletions

View File

@ -6767,6 +6767,11 @@ that range. See `after-change-functions' for more information."
(defun org-element--cache-setup-change-functions ()
"Setup `before-change-functions' and `after-change-functions'."
(when (and (derived-mode-p 'org-mode) org-element-use-cache)
;; Clear copied local cache to avoid extra memory usage.
;; We only use cache stored in the base buffer.
(when (buffer-base-buffer)
(setq-local org-element--cache nil
org-element--headline-cache nil))
(add-hook 'before-change-functions
#'org-element--cache-before-change nil t)
;; Run `org-element--cache-after-change' early to handle cases