From b1b40754fe613e45d67e1295dd89f9f980de8152 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 7 Aug 2024 14:24:05 -0400 Subject: [PATCH] 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 --- modules/lang/org/config.el | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index e677e610d..13b0b504a 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -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 buffers." :around #'org-get-agenda-file-buffer - (let ((recentf-exclude (list (lambda (_file) t))) - (doom-inhibit-large-file-detection t) - org-startup-indented - org-startup-folded - vc-handled-backends - org-mode-hook - find-file-hook) - (let ((buf (funcall fn file))) - (if buf - (with-current-buffer buf - (add-hook 'doom-switch-buffer-hook #'+org--restart-mode-h - nil 'local))) - buf))) + (if-let (buf (org-find-base-buffer-visiting file)) + buf + (let ((recentf-exclude (list (lambda (_file) t))) + (doom-inhibit-large-file-detection t) + org-startup-indented + org-startup-folded + vc-handled-backends + org-mode-hook + enable-local-variables + find-file-hook) + (let ((buf (funcall fn file))) + (when buf + (with-current-buffer buf + (add-hook 'doom-switch-buffer-hook #'+org--restart-mode-h + nil 'local))) + buf)))) (defadvice! +org--fix-inconsistent-uuidgen-case-a (uuid) "Ensure uuidgen is always lowercase (consistent) regardless of system.