From: Eshel Yaron Date: Sat, 3 Feb 2024 15:09:15 +0000 (+0100) Subject: Add annotations for bookmark completion candidates X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c7a2a73786dd217d0f04162f80edeae55ee0cab9;p=emacs.git Add annotations for bookmark completion candidates * lisp/bookmark.el (bookmark--affixation): New function. (bookmark-completing-read): Use it as 'affixation-function'. --- diff --git a/lisp/bookmark.el b/lisp/bookmark.el index b8e1fcbf70d..976f1bc1886 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -558,6 +558,33 @@ is ordered from most recently created to least recently created bookmark." (t (time-less-p ty tx))))))) (t copy)))) +(defun bookmark--affixation (names) + "Return completion affixations for bookmark name list NAMES." + (let ((max-name 0) + (max-type 0) + (all nil) + (res nil)) + (dolist (name names) + (setq max-name (max max-name (string-width name))) + (let* ((bmrk (assoc name bookmark-alist)) + (type (bookmark-type-from-full-record bmrk)) + (type (if (and type (not (string-empty-p type))) type "File"))) + (setq max-type (max max-type (string-width type))) + (push (list name type (bookmark-get-last-modified bmrk)) all))) + (pcase-dolist (`(,name ,type ,lmod) all) + (push (list name "" + (propertize + (concat (make-string (- (+ max-name 2) (string-width name)) ?\s) + type + (when lmod + (concat (make-string (- (+ max-type 2) + (string-width type)) + ?\s) + (format-time-string "%Y-%m-%d %T" lmod)))) + 'face 'completions-annotations)) + res)) + res)) + (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 @@ -583,7 +610,9 @@ If DEFAULT is nil then return empty string for empty input." bookmark-alist `((category . bookmark) (narrow-completions-function - . bookmark-narrow-completions-by-type))) + . bookmark-narrow-completions-by-type) + ,@(when completions-detailed + '((affixation-function . bookmark--affixation))))) nil 0 nil 'bookmark-history default))))) (defun bookmark-narrow-completions-by-type () @@ -591,7 +620,7 @@ If DEFAULT is nil then return empty string for empty input." (let* ((get-type (lambda (bmk-record) (let ((res (bookmark-type-from-full-record bmk-record))) - (if (and res (not (string-empty-p res))) res "Regular")))) + (if (and res (not (string-empty-p res))) res "File")))) (types (delete-dups (mapcar get-type bookmark-alist))) (type (completing-read "Keep bookmark completions of type: " types nil t)))