From a6c57fd4fdd99e9e0af2736bbd61335e06bc5b0e Mon Sep 17 00:00:00 2001 From: Marien Zwart Date: Tue, 3 Mar 2026 21:39:34 +1100 Subject: [PATCH] fix: save after recentf-cleanup on exit Doom adds `recentf-cleanup` to `kill-emacs-hook`, but that function only cleans up `recentf-list` without saving it to disk: saving is handled by `recentf-save-list`. `recentf-mode` adds `recentf-save-list` to `kill-emacs-hook` as well... but it only adds that hook when `recentf-mode` is enabled, which means `recentf-save-list` ends up before `recentf-cleanup` on `kill-emacs-hook`, rendering the cleanup ineffective. This is normally barely noticable, but with many paths on (slow) network filesystems on `recentf-list` the cleanup can get slow enough to be annoying. Fix it by passing a priority to `add-hook`. This leaves an ineffective cleanup call if we exit Emacs with recentf-mode disabled, but that should normally only happen if we exit Emacs without opening a file (`doom-first-file-hook` enables recentf-mode). If that's an issue, we could add a function to `recentf-mode-hook` which in turn adds to `emacs-term-hook`, but that seems too complicated for little gain. --- lisp/doom-editor.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lisp/doom-editor.el b/lisp/doom-editor.el index d3cabd90b..55f671695 100644 --- a/lisp/doom-editor.el +++ b/lisp/doom-editor.el @@ -320,7 +320,10 @@ tell you about it. Very annoying. This prevents that." ;; The most sensible time to clean up your recent files list is when you quit ;; Emacs (unless this is a long-running daemon session). (setq recentf-auto-cleanup (if (daemonp) 300)) - (add-hook 'kill-emacs-hook #'recentf-cleanup) + ;; Use a negative depth value because we need `recentf-cleanup' to run before + ;; `recentf-save-list' to be effective, which `recentf-mode' will only add to + ;; `kill-emacs-hook' once it is enabled. + (add-hook 'kill-emacs-hook #'recentf-cleanup -50) ;; Otherwise `load-file' calls in `recentf-load-list' pollute *Messages* (advice-add #'recentf-load-list :around #'doom-shut-up-a))