[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/icomplete-vertical-mode-improvements 0337e73 10/10: Add annotati
From: |
João Távora |
Subject: |
scratch/icomplete-vertical-mode-improvements 0337e73 10/10: Add annotation capability to icomplete-vertical-mode |
Date: |
Fri, 28 May 2021 06:10:07 -0400 (EDT) |
branch: scratch/icomplete-vertical-mode-improvements
commit 0337e73e191bfd87c8e231174f5947776e575724
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Add annotation capability to icomplete-vertical-mode
Co-authored-by Daniel Mendler <mail@daniel-mendler.de>
* lisp/icomplete.el (icomplete--affixate): New helper.
(icomplete--render-vertical): Use it. Rework.
(icomplete-completions): Pass md to icomplete--render-vertical.
---
lisp/icomplete.el | 66 +++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 55 insertions(+), 11 deletions(-)
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index b8ebb74..befcae5 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -697,6 +697,29 @@ See `icomplete-mode' and `minibuffer-setup-hook'."
(put-text-property 0 1 'cursor t text)
(overlay-put icomplete-overlay 'after-string text))))))))
+(defun icomplete--affixate (md prospects)
+ "Affixate PROSPECTS given completion metadata MD.
+Return a list of (COMP PREFIX SUFFIX)."
+ (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))))
+ (cond (aff-fun
+ (funcall aff-fun prospects))
+ (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))))
+
(cl-defun icomplete--render-vertical (comps md)
;; This is loopapalooza
;;
@@ -747,16 +770,37 @@ See `icomplete-mode' and `minibuffer-setup-hook'."
(setq neighbour (pop succs)) into after
while neighbour
finally
- (cl-return
- (concat " " icomplete-separator
- (mapconcat
- #'identity
- (nconc before
- (list
- (propertize (car comps) 'face
- 'icomplete-selected-match)))
- after)
- icomplete-separator)))))
+ ;; Now figure out spacing and layout
+ ;;
+ (cl-loop
+ with torender
+ = (nconc before
+ (list
+ (propertize (car comps) 'face
+ 'icomplete-selected-match))
+ after)
+ with triplets = (icomplete--affixate md torender)
+ initially (when (eq triplets torender)
+ (cl-return-from icomplete--render-vertical
+ (concat
+ " \n"
+ (mapconcat #'identity torender icomplete-separator))))
+ for (comp prefix) in triplets
+ maximizing (length prefix) into max-prefix-len
+ maximizing (length comp) into max-comp-len
+ finally
+ ;; Finally, render
+ ;;
+ (cl-return-from icomplete--render-vertical
+ (concat
+ " \n"
+ (cl-loop for (comp prefix suffix) in triplets
+ concat prefix
+ concat (make-string (- max-prefix-len (length prefix)) ? )
+ concat comp
+ concat (make-string (- max-comp-len (length comp)) ? )
+ concat suffix
+ concat icomplete-separator))))))
;;;_ > icomplete-completions (name candidates predicate require-match)
(defun icomplete-completions (name candidates predicate require-match)
@@ -802,7 +846,7 @@ matches exist."
(progn ;;(debug (format "Candidates=%S field=%S" candidates name))
(format " %sNo matches%s" open-bracket close-bracket))
(if icomplete-vertical-mode
- (icomplete--render-vertical comps)
+ (icomplete--render-vertical comps md)
(let* ((last (if (consp comps) (last comps)))
;; Save the "base size" encoded in `comps' then
;; removing making `comps' a proper list.
- branch scratch/icomplete-vertical-mode-improvements created (now 0337e73), João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements d3b85d0 04/10: * lisp/icomplete.el (icomplete--render-vertical): Simplify slightly., João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements 136f71b 02/10: Distinguish fido-mode from icomplete-mode verticality, João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements 82f8a3d 03/10: Fix an edge case bug in icomplete.el where base-size wasn't restored, João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements 776633a 01/10: Improve icomplete-vertical-mode, João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements f751980 05/10: Don't break icomplete-vertical-mode scrolling when moving non-destructively, João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements 24ddc91 07/10: Rename icomplete-rotate to icomplete-scroll, for clarity, João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements 94368e2 06/10: Adjust scrolling behaviour of icomplete-vertical-mode, João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements f7b22c0 08/10: Simplify icomplete-vertical-mode scrolling implementation, João Távora, 2021/05/28
- scratch/icomplete-vertical-mode-improvements 0337e73 10/10: Add annotation capability to icomplete-vertical-mode,
João Távora <=
- scratch/icomplete-vertical-mode-improvements 37f0362 09/10: Update NEWS, João Távora, 2021/05/28