diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2021-10-11 07:59:21 +0200 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2021-10-11 08:00:41 +0200 |
| commit | 94bd4c1d62ddf00e2bfd9357e5938f718b4f591d (patch) | |
| tree | e822959e5d753699061f9679b6dd52c5c1cbc31c | |
| parent | b9df3648e30282a42b0c72158e3f354234fd41ff (diff) | |
Revert "Do not reorder candidates with the input prefix before the others"
This reverts commit 98241803d1e2e7b422fc9606fe5fc6ab305e93bc.
| -rw-r--r-- | corfu.el | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -463,6 +463,36 @@ completion began less than that number of seconds ago." (and (= (length x) (length y)) (string< x y)))) +(defmacro corfu--partition! (list form) + "Evaluate FORM for every element and partition LIST." + (let ((head1 (make-symbol "head1")) + (head2 (make-symbol "head2")) + (tail1 (make-symbol "tail1")) + (tail2 (make-symbol "tail2"))) + `(let* ((,head1 (cons nil nil)) + (,head2 (cons nil nil)) + (,tail1 ,head1) + (,tail2 ,head2)) + (while ,list + (if (let ((it (car ,list))) ,form) + (progn + (setcdr ,tail1 ,list) + (pop ,tail1)) + (setcdr ,tail2 ,list) + (pop ,tail2)) + (pop ,list)) + (setcdr ,tail1 (cdr ,head2)) + (setcdr ,tail2 nil) + (setq ,list (cdr ,head1))))) + +(defun corfu--move-prefix-candidates-to-front (field candidates) + "Move CANDIDATES which match prefix of FIELD to the beginning." + (let* ((word (car (split-string field))) + (len (length word))) + (corfu--partition! candidates + (and (>= (length it) len) + (eq t (compare-strings word 0 len it 0 len)))))) + (defun corfu--filter-files (files) "Filter FILES by `completion-ignored-extensions'." (let ((re (concat "\\(?:\\(?:\\`\\|/\\)\\.\\.?/\\|" @@ -499,6 +529,7 @@ completion began less than that number of seconds ago." (setq all (if-let (sort (corfu--metadata-get metadata 'display-sort-function)) (funcall sort all) (sort all #'corfu--sort-predicate))) + (setq all (corfu--move-prefix-candidates-to-front field all)) (when (and completing-file (not (string-suffix-p "/" field))) (setq all (corfu--move-to-front (concat field "/") all))) (setq all (corfu--move-to-front field all)) |
