From 04e7c6da34df6b60e253a35b9baa3eba4062617f Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Sat, 22 May 2021 22:41:27 +0200 Subject: [PATCH] (icomplete-vertical-mode): Add support for affixations and annotations Fix bug#48013 * lisp/icomplete.el (icomplete--affixate): Add function, which annotates the currently visible candidates, given the `affixation-function` or `annotation-function` specified by the completion metadata. (icomplete-completions): Use the new function. --- lisp/icomplete.el | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/lisp/icomplete.el b/lisp/icomplete.el index 91bbb60013..83003fd5f3 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el @@ -666,6 +666,28 @@ icomplete-exhibit (put-text-property 0 1 'cursor t text) (overlay-put icomplete-overlay 'after-string text)))))))) +(defun icomplete--affixate (md prospects) + "Affixate PROSPECTS with prefixes and suffixes, given completion metadata MD." + (let ((aff-fun (or (completion-metadata-get md 'affixation-function) + (plist-get completion-extra-properties :affixation-function))) + (ann-fun (or (completion-metadata-get md 'annotation-function) + (plist-get completion-extra-properties :annotation-function)))) + (if aff-fun + (funcall aff-fun prospects) + (if ann-fun + (mapcar + (lambda (comp) + (let ((suffix (or (funcall ann-fun comp) ""))) + (list comp "" + ;; The default completion UI adds the + ;; `completions-annotations' face if no + ;; other faces are present. + (if (text-property-not-all 0 (length suffix) 'face nil suffix) + suffix + (propertize suffix 'face 'completions-annotations))))) + prospects) + prospects)))) + ;;;_ > icomplete-completions (name candidates predicate require-match) (defun icomplete-completions (name candidates predicate require-match) "Identify prospective candidates for minibuffer completion. @@ -814,14 +836,18 @@ icomplete-completions ;; is cached. (if last (setcdr last base-size)) (if prospects - (concat determ - (if icomplete-vertical-mode " \n" "{") - (mapconcat 'identity prospects (if icomplete-vertical-mode - "\n" - icomplete-separator)) - (unless icomplete-vertical-mode - (concat (and limit (concat icomplete-separator ellipsis)) - "}"))) + (if icomplete-vertical-mode + (concat determ " \n" + (mapconcat + (lambda (comp) + (if (consp comp) + (concat (cadr comp) (car comp) (caddr comp)) + comp)) + (icomplete--affixate md prospects) + "\n")) + (concat determ "{" + (mapconcat 'identity prospects icomplete-separator) + (and limit (concat icomplete-separator ellipsis) "}"))) (concat determ " [Matched]")))))) ;;; Iswitchb compatibility -- 2.20.1