Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get list of recent files in GNU Emacs?

Tags:

emacs

ide

When I use Emacs I want to be able to easily display and navigate through a list of files I worked on from not just the current session but from previous sessions. (BTW, running Emacs 22.2 on Windows)

like image 334
Ray Avatar asked Sep 08 '08 18:09

Ray


People also ask

How do I find files in Emacs?

To find a file in Emacs, you use the C-x C-f ( find-file ) command.

What is the Emacs command to save a file?

1) Saving Files in Emacs Emacs allows you to save the contents to the current buffers by hitting the keys Ctrl + x followed by Ctrl + s. Users can also save the current buffer to some other file name by hitting the keys Ctrl + x, followed by Ctrl + w.


2 Answers

From Joe Grossberg's blog (no longer available):

But if you're using GNU Emacs 21.2 (the latest version, which includes this as part of the standard distro), you can just put the following lines into your .emacs file

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

Then, when you launch emacs, hit CTRL-X CTRL-R. It will show a list of the recently-opened files in a buffer. Move the cursor to a line and press ENTER. That will open the file in question, and move it to the top of your recent-file list.

(Note: Emacs records file names. Therefore, if you move or rename a file outside of Emacs, it won't automatically update the list. You'll have to open the renamed file with the normal CTRL-X CTRL-F method.)

Jayakrishnan Varnam has a page including screenshots of how this package works.

Note: You don't need the (require 'recentf) line.

like image 69
Ben Collins Avatar answered Sep 19 '22 14:09

Ben Collins


Even if you don't have recentf turned on, Emacs is saving a list of files entered via the minibuffer in the variable file-name-history. Also, executing (savehist-mode 1) in your .emacs file makes that variable persist across invocations of Emacs.

So here's a little function that displays the files that actually exist from that list (anyone is welcome to use/build on this):

(defun dir-of-recent-files ()   "See the list of recently entered files in a Dired buffer."   (interactive)   (dired (cons       "*Recent Files*"       (seq-filter        'file-exists-p        (delete-dups         (mapcar (lambda (s) (string-trim-right s "/*"))             file-name-history)         ))))   ) 

I find this quite useful and have it bound to one of those little special function keys on my desktop keyboard. (And so I have not seen the point of turning on recentf...)

like image 36
Glen Whitney Avatar answered Sep 17 '22 14:09

Glen Whitney