emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/corfu 94bd4c1: Revert "Do not reorder candidates with t


From: ELPA Syncer
Subject: [elpa] externals/corfu 94bd4c1: Revert "Do not reorder candidates with the input prefix before the others"
Date: Mon, 11 Oct 2021 02:57:08 -0400 (EDT)

branch: externals/corfu
commit 94bd4c1d62ddf00e2bfd9357e5938f718b4f591d
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Revert "Do not reorder candidates with the input prefix before the others"
    
    This reverts commit 98241803d1e2e7b422fc9606fe5fc6ab305e93bc.
---
 corfu.el | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/corfu.el b/corfu.el
index 51cb9fe..da74eb1 100644
--- a/corfu.el
+++ b/corfu.el
@@ -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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]