Does Emacs have a team to visit a recently opened file?

Does Emacs have a command to open a recently opened file? How visit-most-recent-file?

Please note that I do not want to view the list of recent files, and then select one of them. I want to automatically visit the recently opened.

It would be great to visit a recently opened file (which is no longer in the current buffer) with a single keystroke. And then you can visit the next recently opened file by pressing the key again, etc.

So, by pressing this key four times (for example A-UP), I can automatically open the first four files in the list of recent files.

I can somehow do this by viewing the latest files by pressing C-x C-f UP RET, but it would be great to do this with a single keystroke (for example, A-UP).

+5
source share
2 answers

Creating a pokita answer,

(defun visit-most-recent-file ()
  "Visits the most recently open file in `recentf-list' that is not already being visited."
  (interactive)
  (let ((buffer-file-name-list (mapcar 'buffer-file-name (buffer-list)))
        most-recent-filename)
    (dolist (filename recentf-list)
      (unless (memq filename buffer-file-name-list)
        (setq most-recent-filename filename)
        (return)))
    (find-file most-recent-filename)))

I have not tested a lot.

+3
source

You can do this using the lastf package:

(require 'recentf)
(defvar my-recentf-counter 0)
(global-set-key (kbd "<M-up>")
        (lambda ()
          (interactive)
          (setq my-recentf-counter (1+ my-recentf-counter))
          (recentf-open-most-recent-file my-recentf-counter)))

You will probably have a problem with the fact that there are files in the "recent" list that you are not interested in (temporary material that was saved when you quit Emacs). Use the recentf-exclude variable to exclude these files from the list of recently opened files.

+2
source

All Articles