fix(org): don't optimize already-open agenda buffers

`org-map-entries` uses `org-get-agenda-file-buffer` to visit agenda
files, and Doom optimizes the latter to open those org buffers in a
limited capacity (since buffers opened this way are rarely visible, and
full initialization of them is very expensive), deferring their
initialization until the user interactively switches to the buffer
later.

However, if an agenda buffer has already been visited, opening it with
`org-get-agenda-file-buffer` with all these disabled initializations
could have unpredictable effects on whatever the user is doing in their
`org-map-entries` call. Since these optimizations aren't needed for
agenda buffers that already exist, I'll no-op `+org--restart-mode-h` in
those cases.

Fix: #7979
This commit is contained in:
Henrik Lissner 2024-08-07 14:24:05 -04:00
parent e3fdfee1c5
commit b1b40754fe
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -799,19 +799,22 @@ via an indirect buffer."
`org-mode' when they're switched to so they can grow up to be fully-fledged `org-mode' when they're switched to so they can grow up to be fully-fledged
org-mode buffers." org-mode buffers."
:around #'org-get-agenda-file-buffer :around #'org-get-agenda-file-buffer
(if-let (buf (org-find-base-buffer-visiting file))
buf
(let ((recentf-exclude (list (lambda (_file) t))) (let ((recentf-exclude (list (lambda (_file) t)))
(doom-inhibit-large-file-detection t) (doom-inhibit-large-file-detection t)
org-startup-indented org-startup-indented
org-startup-folded org-startup-folded
vc-handled-backends vc-handled-backends
org-mode-hook org-mode-hook
enable-local-variables
find-file-hook) find-file-hook)
(let ((buf (funcall fn file))) (let ((buf (funcall fn file)))
(if buf (when buf
(with-current-buffer buf (with-current-buffer buf
(add-hook 'doom-switch-buffer-hook #'+org--restart-mode-h (add-hook 'doom-switch-buffer-hook #'+org--restart-mode-h
nil 'local))) nil 'local)))
buf))) buf))))
(defadvice! +org--fix-inconsistent-uuidgen-case-a (uuid) (defadvice! +org--fix-inconsistent-uuidgen-case-a (uuid)
"Ensure uuidgen is always lowercase (consistent) regardless of system. "Ensure uuidgen is always lowercase (consistent) regardless of system.