branch: externals/vertico
commit d65a0db53edeb65aee0e3c2b5f8332ffc3381ba8
Author: Daniel Mendler <[email protected]>
Commit: Daniel Mendler <[email protected]>
vertico--defined-sort: Minor cleanup
---
vertico.el | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/vertico.el b/vertico.el
index b0acfcdc83..362b6f1fdd 100644
--- a/vertico.el
+++ b/vertico.el
@@ -231,18 +231,16 @@ The value should lie between 0 and vertico-count/2."
The function is configured by BY, BSIZE, BINDEX, BPRED and PRED."
`(defun ,(intern (mapconcat #'symbol-name `(vertico sort ,@by) "-"))
(candidates)
,(concat "Sort candidates by " (mapconcat #'symbol-name by ", ") ".")
- (let* ((buckets (make-vector ,bsize nil))
- ,@(and (eq (car by) 'history) '((hhash (vertico--history-hash))
(hcands))))
+ (let* ((buckets (make-vector ,bsize nil)) last
+ ,@(and (eq (car by) 'history) '((hhash (vertico--history-hash))
hcands)))
(dolist (% candidates)
;; Find recent candidate in history or fill bucket
(,@(if (not (eq (car by) 'history)) `(progn)
`(if-let ((idx (gethash % hhash))) (push (cons idx %) hcands)))
- (push % (aref buckets (min ,(1- bsize) ,bindex)))))
+ (let ((i ,bindex)) (if (< i ,bsize) (push % (aref buckets i)) (push
% last)))))
(nconc ,@(and (eq (car by) 'history) '((vertico--sort-decorated
hcands)))
- (mapcan (lambda (bucket) (sort bucket #',bpred))
- (nbutlast (append buckets nil)))
- ;; Last bucket needs special treatment
- (sort (aref buckets ,(1- bsize)) #',pred)))))
+ (mapcan (lambda (bucket) (sort bucket #',bpred)) buckets)
+ (sort last #',pred)))))
(vertico--define-sort (history length alpha) 48 (length %) string<
vertico--length-string<)
(vertico--define-sort (history alpha) 32 (if (equal % "") 0 (/ (aref % 0) 4))
string< string<)