;;; 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)