Emacs Weekly Tip #2: Recent Files with recentf

In my daily Emacs activities I open a lot of files. However, during the week I am normally opening the same files as I’m generally working on the same stuff. Emacs’s Recent Files (recentf) feature generates a list of my recently used files and allows me to display that list so I can quickly open any of them.

To enable recentf mode, add the following into your Emacs init file (which you are version controlling right?)

;; recentf stuff
(require 'recentf)
(recentf-mode 1)
(setq recentf-max-menu-items 25)
(global-set-key "C-x C-r" 'recentf-open-files)

If you use Tramp a lot you may want to disable the auto-cleanup command for Recentf. This is simply because every now an then, if enabled, the auto-cleanup feature scans a list of your recent files, and tries to stat them to see if they should remain in the list. Obviously, if it tries to stat any remote files this may cause your system to temporarily hang.

;; recentf stuff
(require 'recentf)
(setq recentf-auto-cleanup 'never) ;; disable before we start recentf!
(recentf-mode 1)
(setq recentf-max-menu-items 25)
(global-set-key "C-x C-r" 'recentf-open-files)

Now use Emacs for a bit to generate a list of your recently used files. Next time you open Emacs, simply hit C-x C-r and you’ll be greeted with a list of your recently used files.

A great time saver.

For more info, visit the Emacs Wiki page.