Subject: bug#56148: [PATCH] New command recentf-open

From: Stefan Kangas <[email-masked]>
Date: Wed, 22 Jun 2022 16:57:43 +0200

Severity: wishlist

In recentf-mode, I think it would be useful to provide a command to
open recent files using the minibuffer.  Please see the attached
patch.
From 45b08e7b263d5804a18ccc403df2341c025b88ed Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Wed, 22 Jun 2022 16:54:40 +0200
Subject: [PATCH] New command recentf-open

* lisp/recentf.el (recentf-open): New command.
(recentf): New alias.
---
 etc/NEWS        |  5 +++++
 lisp/recentf.el | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 40658559d7..24028ac213 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1860,6 +1860,11 @@ the project by a VC project based on that VCS.
 They are shortened with 'abbreviate-file-name'.  Customize the user
 option 'recentf-menu-filter' to nil to get unabbreviated file names.
 
+---
+*** New command 'recentf-open'.
+Instead of using a menu, this command prompts for a recently opened
+file in the minibuffer, and visits it.
+
 ---
 ** The autoarg.el library is now marked obsolete.
 This library provides the 'autoarg-mode' and 'autoarg-kp-mode' minor
diff --git a/lisp/recentf.el b/lisp/recentf.el
index 1005d4855f..9e8b858bb3 100644
--- a/lisp/recentf.el
+++ b/lisp/recentf.el
@@ -465,6 +465,25 @@ recentf-directory-compare
         (recentf-string-lessp (file-name-nondirectory f1)
                               (file-name-nondirectory f2))
       (recentf-string-lessp d1 d2))))
+
+
+;;; Open files
+;;
+
+(defun recentf-open (file)
+  "Prompt for FILE in `recentf-list' and visit it.
+Enable `recentf-mode' if it isn't already."
+  (interactive
+   (list
+    (progn (unless recentf-mode (recentf-mode 1))
+           (completing-read (format-prompt "Open recent file" nil)
+                            (mapcar #'abbreviate-file-name recentf-list)
+                            nil t))))
+  (when file
+    (funcall recentf-menu-action file)))
+
+(defalias 'recentf 'recentf-open)
+
 
 ;;; Menu building
 ;;
-- 
2.30.2