How to completely disable recentf-cleanup (especially in TRAMP)?

Frequently recent files SPC f r will get cleared. I’ve been trying to solve this for years, but none of the solutions I have tried have had an effect:

https://emacs.stackexchange.com/questions/24857/disable-remote-file-cleanup-in-recentf

https://stackoverflow.com/questions/880625/stop-tramp-mode-running-on-emacs-startup

I’m uncertain exactly what is triggering recentf-cleanup, but it seems to happen often after resuming my machine from suspend when the network isn’t online yet and when I have TRAMP files open.

Here is a config.el snippet from my various attempts at disabling recentf-cleanup:

(setq recentf-keep '('file-remote-p))
(run-at-time (current-time) 300 'recentf-save-list)
(require 'recentf)
(setq recentf-auto-cleanup 'never)
(add-hook 'kill-emacs-hook #'recentf-cleanup)

System information


Loading data dump...

recentf-keep already contains recentf-keep-default-predicate by default, which performs a file-remote-p check, so you shouldn’t have to do anything except make sure you kill Emacs properly (if you sigkill or sigterm the process, kill-emacs-hook will never trigger).

What’s more, in your snippet you’ve double-quoted file-remote-p while setting recentf-keep, making it an invalid file, which recentf will ignore.

If nothing else works, you could try:

(after! recentf
  (add-to-list 'recentf-keep #'file-remote-p))