branch: externals/vertico commit 836a8a7dc1e5f1f9d03f1cab7cbad6a6376fa6d8 Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
vertico-quick: Extract vertico-quick--keys function --- extensions/vertico-quick.el | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/extensions/vertico-quick.el b/extensions/vertico-quick.el index 9a8ea01b01..ef4f93fc9e 100644 --- a/extensions/vertico-quick.el +++ b/extensions/vertico-quick.el @@ -68,29 +68,32 @@ (defvar-local vertico-quick--list nil) (defvar-local vertico-quick--first nil) -(defun vertico-quick--format-candidate (orig cand prefix suffix index start) - "Format candidate, see `vertico--format-candidate' for arguments." +(defun vertico-quick--keys (index) + "Format keys for INDEX." (let* ((fst (length vertico-quick1)) (snd (length vertico-quick2)) - (len (+ fst snd)) - (idx (- index start)) - (keys (if (>= idx fst) - (let ((first (elt vertico-quick2 (mod (/ (- idx fst) len) snd))) - (second (elt (concat vertico-quick1 vertico-quick2) (mod (- idx fst) len)))) - (cond - ((eq first vertico-quick--first) - (push (cons second index) vertico-quick--list) - (concat " " (propertize (char-to-string second) 'face 'vertico-quick1))) - (vertico-quick--first " ") - (t - (push (cons first (list first)) vertico-quick--list) - (concat (propertize (char-to-string first) 'face 'vertico-quick1) - (propertize (char-to-string second) 'face 'vertico-quick2))))) - (let ((first (elt vertico-quick1 (mod idx fst)))) - (if vertico-quick--first - " " - (push (cons first index) vertico-quick--list) - (concat (propertize (char-to-string first) 'face 'vertico-quick1) " ")))))) + (len (+ fst snd))) + (if (>= index fst) + (let ((first (elt vertico-quick2 (mod (/ (- index fst) len) snd))) + (second (elt (concat vertico-quick1 vertico-quick2) (mod (- index fst) len)))) + (cond + ((eq first vertico-quick--first) + (push (cons second index) vertico-quick--list) + (concat " " (propertize (char-to-string second) 'face 'vertico-quick1))) + (vertico-quick--first " ") + (t + (push (cons first (list first)) vertico-quick--list) + (concat (propertize (char-to-string first) 'face 'vertico-quick1) + (propertize (char-to-string second) 'face 'vertico-quick2))))) + (let ((first (elt vertico-quick1 (mod index fst)))) + (if vertico-quick--first + " " + (push (cons first index) vertico-quick--list) + (concat (propertize (char-to-string first) 'face 'vertico-quick1) " ")))))) + +(defun vertico-quick--format-candidate (orig cand prefix suffix index start) + "Format candidate, see `vertico--format-candidate' for arguments." + (let ((keys (vertico-quick--keys (- index start)))) (if (bound-and-true-p vertico-flat-mode) (setq keys (replace-regexp-in-string " " "" keys) cand (string-trim cand)