GNU bug report logs - #78596
30.1; recentf-open ought to use a completion table and category

Previous Next

Package: emacs;

Reported by: dino chiesa <dpchiesa <at> hotmail.com>

Date: Mon, 26 May 2025 20:04:02 UTC

Severity: normal

Found in version 30.1

Full log


View this message in rfc822 format

From: Eshel Yaron <me <at> eshelyaron.com>
To: dino chiesa <dpchiesa <at> hotmail.com>
Cc: 78596 <at> debbugs.gnu.org
Subject: bug#78596: 30.1; recentf-open ought to use a completion table and category
Date: Tue, 27 May 2025 16:08:52 +0200
Hi,

dino chiesa <dpchiesa <at> hotmail.com> writes:

> This isn't a bug report, more of an enhancement request.
>
> Summary
> I would like recentf-open to use "Programmed Completion" via 
> a completion function. (see 21.6.7 Programmed Completion)  
> That function ought to return metadata with a category that 
> is specific to recentf.

Good idea.  Could you please check if the following patch works for you?

diff --git a/lisp/recentf.el b/lisp/recentf.el
index a773ea9ec01..006b3159bb9 100644
--- a/lisp/recentf.el
+++ b/lisp/recentf.el
@@ -505,7 +505,9 @@ recentf-open
    (list
     (progn (unless recentf-mode (recentf-mode 1))
            (completing-read (format-prompt "Open recent file" nil)
-                            recentf-list nil t))))
+                            (completion-table-with-metadata
+                             recentf-list '((category . recentf)))
+                            nil t))))
   (when file
     (funcall recentf-menu-action file)))
 


The completion-table-with-metadata function is a new helper function
that is very useful when we just want to enrich some existing completion
table with some metadata.  

We should probably document it in the manual, BTW.  Here's a draft:

diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi
index 3cc206d2e1d..2e91f2c21b4 100644
--- a/doc/lispref/minibuf.texi
+++ b/doc/lispref/minibuf.texi
@@ -2123,6 +2123,15 @@ Programmed Completion
 when a slow operation is involved, such as calling an external process.
 @end defun
 
+@defun completion-table-with-metadata table metadata
+This function creates a completion table that behaves like the existing
+completion table @var{table}, except with additional metadata given in
+@var{metadata}, which is an alist of completion metadata.  If
+@var{table} already provides completion metadata, it is merged with
+@var{metadata}, giving precedence to @var{metadata} if an entry appears
+both in @var{metadata} and in the metadata that @var{table} produces.
+@end defun
+
 @node Completion in Buffers
 @subsection Completion in Ordinary Buffers
 @cindex inline completion



Best,

Eshel




This bug report was last modified 6 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.