Subject: 29.0.50; [PATCH] Add completions details to Bookmarks

From: Gabriel <[email-masked]>
Date: Fri, 25 Nov 2022 16:19:38 -0300

Severity: wishlist

Description:

Add completions details (see `completions-detailed') to Bookmarks.  It
affects all bookmark functions that make uses of
`bookmark-completing-read' (e.g.: `bookmark-jump', `bookmark-relocate',
`bookmark-insert-location', `bookmark-rename' etc).  See also [1].

[1] https://lists.gnu.org/archive/html/emacs-devel/2022-11/msg00995.html

>From 188d924aaa8842c85a4d4206d6c71ca31727240e Mon Sep 17 00:00:00 2001
From: Gabriel do Nascimento Ribeiro <[email-masked]>
Date: Fri, 25 Nov 2022 16:07:14 -0300
Subject: [PATCH 1/1] Add completions details to Bookmarks

* lisp/bookmark.el (bookmark-completing-read--collection)
(bookmark-completing-read--affixation-function): New auxiliary
functions to add completion details to bookmark-completing-read.
(bookmark-completing-read): Make use of new auxiliary function.
---
 lisp/bookmark.el | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index 7f3a264f53..9050668f4f 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -541,6 +541,23 @@ bookmark-maybe-sort-alist
                                 (t (time-less-p ty tx)))))))
           (t copy))))
 
+(defun bookmark-completing-read--collection (string pred action)
+  (if (eq action 'metadata)
+      `(metadata (category . bookmark)
+                 ,@(when completions-detailed
+                     '((affixation-function . bookmark-completing-read--affixation-function))))
+    (complete-with-action action bookmark-alist string pred)))
+
+(defun bookmark-completing-read--affixation-function (bookmarks)
+  (seq-map (lambda (record)
+             (list record
+                   nil
+                   (propertize (format "  %-11s  %s"
+                                       (or (bookmark-type-from-full-record record) "")
+                                       (bookmark-location record))
+                               'face 'completions-annotations)))
+           bookmarks))
+
 (defun bookmark-completing-read (prompt &optional default)
   "Prompting with PROMPT, read a bookmark name in completion.
 PROMPT will get a \": \" stuck on the end no matter what, so you
@@ -555,14 +572,9 @@ bookmark-completing-read
     (let* ((completion-ignore-case bookmark-completion-ignore-case)
            (default (unless (equal "" default) default)))
       (completing-read (format-prompt prompt default)
-                       (lambda (string pred action)
-                         (if (eq action 'metadata)
-                             '(metadata (category . bookmark))
-                             (complete-with-action
-                              action bookmark-alist string pred)))
+                       #'bookmark-completing-read--collection
                        nil 0 nil 'bookmark-history default))))
 
-
 (defmacro bookmark-maybe-historicize-string (string)
   "Put STRING into the bookmark prompt history, if caller non-interactive.
 We need this because sometimes bookmark functions are invoked
-- 
2.34.1

---
Gabriel