From: Eshel Yaron Date: Thu, 20 Jun 2024 16:41:55 +0000 (+0200) Subject: Sort and annotate 'minibuffer-set-action' completions X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=cb52499fe51732d9bd20aecffd484da61eea4d4a;p=emacs.git Sort and annotate 'minibuffer-set-action' completions --- diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 582236e6de4..62c457deb12 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1171,6 +1171,7 @@ styles for specific categories, such as files, buffers, etc." (multiple-choice (styles . (basic substring)) (sort-function . identity)) (calendar-month (sort-function . identity)) (keybinding (sort-function . minibuffer-sort-alphabetically)) + (function (sort-function . minibuffer-sort-alphabetically)) (library (sort-function . minibuffer-sort-alphabetically))) "Default settings for specific completion categories. @@ -4362,6 +4363,22 @@ possible completions." (setq done t) (message "Done")))))) +(defun minibuffer--set-action-affixation (cands) + "Annotate completion candidates CANDS with their documentation strings." + (let ((max (seq-max (cons 0 (mapcar #'string-width cands))))) + (mapcar + (lambda (cand) + (let ((sym (intern cand))) + (list cand "" + (if-let ((doc (ignore-errors + (documentation sym)))) + (concat (make-string (1+ (- max (string-width cand))) ?\s) + (propertize + (substring doc 0 (string-search "\n" doc)) + 'face 'completions-annotations)) + "")))) + cands))) + (defvar minibuffer-action-history nil "History list for `minibuffer-set-action'.") @@ -4369,7 +4386,12 @@ possible completions." "Set minibuffer action function of current minibuffer to ACTION-FN." (interactive (let ((enable-recursive-minibuffers t)) - (list (completing-read "Action function: " obarray #'fboundp + (list (completing-read "Action function: " + (completion-table-with-metadata + obarray + '((category . function) + (affixation-function . minibuffer--set-action-affixation))) + #'fboundp nil nil 'minibuffer-action-history))) minibuffer-mode) (when (stringp action-fn) (setq action-fn (read action-fn)))