Reputation: 6368
I use an Emacs library called buffer-stack to page through my currently open buffers. It's great because it allows me to exclude uninteresting buffers like Messages and browse through only the buffers with content I've created. I browse through these buffers with a single keystroke, A-right.
I also use Ido-mode to browse through the names of recently opened files.
However, I'd like to be able to browse through not just the filenames, but the actual files, preferably with a single keystroke.
How can I browse through recently opened files?
Upvotes: 0
Views: 682
Reputation: 7874
Here are two possible solutions (depending on exactly the use case you want).
(defun zin/open-recent-file ()
"Open the most recent currently closed file.
This will omit currently open files, instead it will retrieve the
next oldest file in recentf-list."
(interactive)
(let* ((count 0)
(recent recentf-list)
(r-length (length recent))
(buffers (mapcar 'buffer-file-name (buffer-list))))
;; Compare next file on the list to open buffers, if open skip it.
(while (member (nth count recent)
buffers)
(setq count (1+ count))
(if (= r-length count)
(error "All recent buffers already open")))
(find-file (nth count recent))))
(lexical-let ((recent-count 0))
(defun zin/visit-recent-file ()
"Visit files on the recentf-list in descending order.
This will work backwards through recentf-list visiting each file
in turn."
(interactive)
;; If last command was not to cycle through the files, then start
;; back at the first in the list.
(unless (eq last-command 'zin/visit-recent-file)
(setq recent-count 0))
;; If current buffer is the current entry on the list, increment.
(if (equal (buffer-file-name) (nth 0 recentf-list))
(setq recent-count (1+ recent-count)))
;; Error if all entries have been processed
(if (= recent-count (length recentf-list))
(error "At oldest recent buffer"))
;; Open appropriate file.
(find-file (nth recent-count recentf-list))))
The first will go through the list of recent files (recentf-list
) and open the next unopened file. The second will use recentf-list
to cycle to the next buffer in the list, until all have been visited then erroring out (since the list order will change as files are reopened).
To have it restart cycling when it reaches the end, just change the (error ...)
to
(setq recent-count 0)
Upvotes: 0
Reputation: 2303
You can use helm-recentf
and its persistent-action
for this purpose.
You can select recent file with helm-recentf
as below.
And you can see file content by pressing Ctrl-z
(persistent-action).
you press Ctrl-z
, then show it content to another window(in this case upper window) temporary.
Please see official document, if you learn about helm
Upvotes: 3