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.
This commit is contained in:
Marien Zwart 2026-03-03 21:39:34 +11:00 committed by Henrik Lissner
parent dc0fc9d4f4
commit a6c57fd4fd

View file

@ -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))