branch: externals/vertico commit a98a6a9a57c6358dce742f21793928969c413367 Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Pass start index to vertico--format-candidate --- extensions/vertico-quick.el | 13 ++++--------- vertico.el | 7 ++++--- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/extensions/vertico-quick.el b/extensions/vertico-quick.el index 2d61588..a1ec63c 100644 --- a/extensions/vertico-quick.el +++ b/extensions/vertico-quick.el @@ -56,17 +56,15 @@ :type 'string :group 'vertico) -(defvar-local vertico-quick--index 0) (defvar-local vertico-quick--list 0) (defvar-local vertico-quick--first nil) -(defun vertico-quick--format-candidate (orig cand prefix suffix index) +(defun vertico-quick--format-candidate (orig cand prefix suffix index start) "Format candidate, see `vertico--format-candidate' for arguments." (let* ((fst (length vertico-quick1)) (snd (length vertico-quick2)) (len (+ fst snd)) - (idx vertico-quick--index)) - (setq vertico-quick--index (1+ idx)) + (idx (- index start))) (funcall orig cand (concat (if (>= idx fst) @@ -87,15 +85,13 @@ " " (concat (propertize (char-to-string first) 'face 'vertico-quick1) " ")))) (make-string (max 1 (- (length prefix) 2)) ?\s)) - suffix - index))) + suffix index start))) ;;;###autoload (defun vertico-quick-jump () "Jump to candidate using quick keys." (interactive) - (cl-letf* ((vertico-quick--index 0) - (vertico-quick--list nil) + (cl-letf* ((vertico-quick--list nil) (key nil) (orig-format (symbol-function #'vertico--format-candidate)) ((symbol-function #'vertico--format-candidate) @@ -104,7 +100,6 @@ (setq key (read-key)) (when (seq-position vertico-quick2 key) (let ((vertico-quick--first key) - (vertico-quick--index 0) (vertico-quick--list)) (vertico--exhibit)) (setq key (+ (lsh key 16) (read-key)))) diff --git a/vertico.el b/vertico.el index 69238da..6b5ea8d 100644 --- a/vertico.el +++ b/vertico.el @@ -426,7 +426,7 @@ See `resize-mini-windows' for documentation." (replace-regexp-in-string "\\`[\t\n ]+\\|[\t\n ]+\\'" "")) max-width 0 nil (cdr vertico-multiline))) -(defun vertico--format-candidate (cand prefix suffix index) +(defun vertico--format-candidate (cand prefix suffix index _start) "Format CAND given PREFIX, SUFFIX and INDEX." (setq cand (concat prefix cand suffix "\n") cand (vertico--flatten-string 'invisible (vertico--flatten-string 'display cand))) @@ -438,8 +438,9 @@ See `resize-mini-windows' for documentation." "Format current candidates with METADATA." (let* ((group-fun (completion-metadata-get metadata 'group-function)) (group-format (and group-fun vertico-group-format (concat vertico-group-format "\n"))) - (index (min (max 0 (- vertico--index (/ vertico-count 2) (if group-format -1 0))) + (start (min (max 0 (- vertico--index (/ vertico-count 2) (if group-format -1 0))) (max 0 (- vertico--total vertico-count)))) + (index start) (candidates (thread-last (seq-subseq vertico--candidates index (min (+ index vertico-count) vertico--total)) @@ -459,7 +460,7 @@ See `resize-mini-windows' for documentation." (setq curr-line (length lines))) (when (string-match-p "\n" cand) (setq cand (vertico--truncate-multiline cand max-width))) - (push (vertico--format-candidate cand prefix suffix index) lines) + (push (vertico--format-candidate cand prefix suffix index start) lines) (setq index (1+ index)))) (setq lines (nreverse lines) index (length lines)) (while (> index vertico-count)