Weekly Emacs tip #26 — Recentf: keep track of recently edited files
Most “ordinary” editors I know keep a list of the most recently opened files in their File menu. Emacs (of course) can have that too, through the built-in
recentf
package. Loading that package adds a submenu called Open Recent to the File menu. Alternatively, one can call M-x recentf
or M-x recentf-open
to open one of those recently visited files.
The number of files that is saved in that list can be set through the variable recentf-max-saved-items
. The default value is 20
, which is enough for me.
My use-package
config below also adds a series of items to the recentf-exclude
list. For example, I don’t want to store files I opened via Tramp (with SSH or via sudo
) in my list of recently edited files. The main reason for this is that I found that having these “remote” files in the list slows Emacs down because it tries to verify if those files are still accessible. As a result, Emacs will ask for the password(s) needed to access those locations. The manual mentions the variable remote-file-name-access-timeout
, which should help to avoid this. It turns out this was added to the recently release Emacs v30.1. I haven’t tested this yet.
The :hook
block in my config is how I enable recentf-mode
. What it does is the following: it adds the call to recentf-mode
to the after-init-hook
variable, which means the function is called once the initialisation of an Emacs session has completed.
(use-package recentf :hook (after-init . recentf-mode) :config (dolist (itm '("^/ssh:" "^/sudo:" "~/.emacs.d/.cache/.*" "recentf$")) (add-to-list 'recentf-exclude itm)) )
No Comments