From e4830ed6b0ca685d4032972544e00dbb568d3b65 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Tue, 16 Jan 2024 13:39:39 +0100 Subject: [PATCH] ; Provide metadata for 'recentf' completions * lisp/recentf.el (recentf-completion-table): New function. (recentf-open): Use it. Allow specifying file names that are not in 'recentf-list', after confirmation. --- lisp/recentf.el | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/lisp/recentf.el b/lisp/recentf.el index dfb783205df..4c8b852197a 100644 --- a/lisp/recentf.el +++ b/lisp/recentf.el @@ -484,18 +484,35 @@ Return non-nil if F1 is less than F2." ;;; Open files ;; +(defun recentf-completion-table (string pred action) + "Completion table for recent file names. + +See Info node `(elisp)Programmed Completion' for the meaning of +STRING, PRED and ACTION." + (if (eq action 'metadata) + `(metadata + ;; Report `recent-file' rather than `file' as the category, so + ;; users can configure the two separately. + (category . recent-file) + ;; Sort candidates by their position in `recentf-list'. + (cycle-sort-function . identity) + (display-sort-function . identity) + ,@(when completions-detailed + '((affixation-function . completion-file-name-affixation)))) + (complete-with-action action recentf-list string pred))) + ;;;###autoload (defun recentf-open (file) - "Prompt for FILE in `recentf-list' and visit it. -Enable `recentf-mode' if it isn't already." + "Open recently visited FILE. + +Interactively, prompt for FILE, and enable `recentf-mode' if it +is not already on." (interactive - (let ((completions-sort nil)) - (list - (progn (unless recentf-mode (recentf-mode 1)) - (completing-read (format-prompt "Open recent file" nil) - recentf-list nil t))))) - (when file - (funcall recentf-menu-action file))) + (progn + (unless recentf-mode (recentf-mode 1)) + (list (completing-read "Open recent file: " + #'recentf-completion-table nil 'confirm)))) + (funcall recentf-menu-action file)) ;;;###autoload (defalias 'recentf 'recentf-open) -- 2.39.5