aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Távora2021-05-25 22:40:40 +0100
committerJoão Távora2021-05-30 17:30:15 +0100
commit638f54187d8fb414a744e5f2af309fcb7dd7eb5b (patch)
tree22ecb5d1807780c99c98183ff20afbe706f5a0d5
parent4b2c73f368ed6f08f374481fd0b0b61b2a804382 (diff)
downloademacs-scratch/icomplete-vertical-mode-improvements.tar.gz
emacs-scratch/icomplete-vertical-mode-improvements.zip
Add annotation capability to icomplete-vertical-modescratch/icomplete-vertical-mode-improvements
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.
-rw-r--r--lisp/icomplete.el61
1 files changed, 51 insertions, 10 deletions
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index 2067a402482..cd7858f3ebc 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -716,7 +716,30 @@ See `icomplete-mode' and `minibuffer-setup-hook'."
716 (safe-length completion-all-sorted-completions)))))) 716 (safe-length completion-all-sorted-completions))))))
717 (overlay-put icomplete-overlay 'after-string text)))))))) 717 (overlay-put icomplete-overlay 'after-string text))))))))
718 718
719(cl-defun icomplete--render-vertical (comps &aux scroll-above scroll-below) 719(defun icomplete--affixate (md prospects)
720 "Affixate PROSPECTS given completion metadata MD.
721Return a list of (COMP PREFIX SUFFIX)."
722 (let ((aff-fun (or (completion-metadata-get md 'affixation-function)
723 (plist-get completion-extra-properties :affixation-function)))
724 (ann-fun (or (completion-metadata-get md 'annotation-function)
725 (plist-get completion-extra-properties :annotation-function))))
726 (cond (aff-fun
727 (funcall aff-fun prospects))
728 (ann-fun
729 (mapcar
730 (lambda (comp)
731 (let ((suffix (or (funcall ann-fun comp) "")))
732 (list comp ""
733 ;; The default completion UI adds the
734 ;; `completions-annotations' face if no
735 ;; other faces are present.
736 (if (text-property-not-all 0 (length suffix) 'face nil suffix)
737 suffix
738 (propertize suffix 'face 'completions-annotations)))))
739 prospects))
740 (prospects))))
741
742(cl-defun icomplete--render-vertical (comps md &aux scroll-above scroll-below)
720 ;; Welcome to loopapalooza! 743 ;; Welcome to loopapalooza!
721 ;; 744 ;;
722 ;; First, be mindful of `icomplete-scroll' and manual scrolls. If 745 ;; First, be mindful of `icomplete-scroll' and manual scrolls. If
@@ -768,14 +791,32 @@ See `icomplete-mode' and `minibuffer-setup-hook'."
768 finally (setq scroll-below scroll-below-aux)) 791 finally (setq scroll-below scroll-below-aux))
769 ;; Now figure out spacing and layout 792 ;; Now figure out spacing and layout
770 ;; 793 ;;
771 (let ((selected (substring (car comps)))) 794 (cl-loop
772 (add-face-text-property 0 (length selected) 795 with selected = (substring (car comps))
773 'icomplete-selected-match 'append selected) 796 initially (add-face-text-property 0 (length selected)
774 (concat " " icomplete-separator 797 'icomplete-selected-match 'append selected)
775 (mapconcat 798 with torender = (nconc scroll-above (list selected) scroll-below)
776 #'identity 799 with triplets = (icomplete--affixate md torender)
777 (nconc scroll-above (list selected) scroll-below) 800 initially (when (eq triplets torender)
778 icomplete-separator)))) 801 (cl-return-from icomplete--render-vertical
802 (concat
803 " \n"
804 (mapconcat #'identity torender icomplete-separator))))
805 for (comp prefix) in triplets
806 maximizing (length prefix) into max-prefix-len
807 maximizing (length comp) into max-comp-len
808 finally return
809 ;; Finally, render
810 ;;
811 (concat
812 " \n"
813 (cl-loop for (comp prefix suffix) in triplets
814 concat prefix
815 concat (make-string (- max-prefix-len (length prefix)) ? )
816 concat comp
817 concat (make-string (- max-comp-len (length comp)) ? )
818 concat suffix
819 concat icomplete-separator))))
779 820
780;;;_ > icomplete-completions (name candidates predicate require-match) 821;;;_ > icomplete-completions (name candidates predicate require-match)
781(defun icomplete-completions (name candidates predicate require-match) 822(defun icomplete-completions (name candidates predicate require-match)
@@ -821,7 +862,7 @@ matches exist."
821 (progn ;;(debug (format "Candidates=%S field=%S" candidates name)) 862 (progn ;;(debug (format "Candidates=%S field=%S" candidates name))
822 (format " %sNo matches%s" open-bracket close-bracket)) 863 (format " %sNo matches%s" open-bracket close-bracket))
823 (if icomplete-vertical-mode 864 (if icomplete-vertical-mode
824 (icomplete--render-vertical comps) 865 (icomplete--render-vertical comps md)
825 (let* ((last (if (consp comps) (last comps))) 866 (let* ((last (if (consp comps) (last comps)))
826 ;; Save the "base size" encoded in `comps' then 867 ;; Save the "base size" encoded in `comps' then
827 ;; removing making `comps' a proper list. 868 ;; removing making `comps' a proper list.