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

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

[elpa] externals/corfu 9824180 1/2: Do not reorder candidates with the i


From: ELPA Syncer
Subject: [elpa] externals/corfu 9824180 1/2: Do not reorder candidates with the input prefix before the others
Date: Wed, 6 Oct 2021 10:57:12 -0400 (EDT)

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

    Do not reorder candidates with the input prefix before the others
    
    * This code was introduced to ease the usage of Orderless, where the input 
must
    not necessarily occur at the beginning. My recommendation is to use an 
Orderless
    style dispatcher instead, where the first word is prefixed with ^ for Corfu.
    Doing this even results in a performance win, since Orderless compiles 
^words in
    a smart way such that prefix filtering takes place inside the completion 
table.
    See https://github.com/oantolin/orderless/issues/79 and
    https://github.com/oantolin/orderless/issues/81.
    
    See the Orderless style dispatcher from the Consult wiki 
https://github.com/minad/consult/wiki:
    
      (defun +orderless-dispatch (pattern index _total)
        (cond
         ;; Treat first component as prefix. This is useful for Corfu 
completion-in-region.
         ((and completion-in-region-mode (= index 0))
          `(orderless-regexp . ,(concat "^" (regexp-quote pattern))))
         ...))
    
    * If you use the basic completion style, the input is already used for 
prefix
    filtering and this change has no effect.
    
    * If you use another completion style which even sorts the candidates 
itself,
    e.g., flex, this change is advantageous since it gives the completion style 
more
    control.
---
 corfu.el | 31 -------------------------------
 1 file changed, 31 deletions(-)

diff --git a/corfu.el b/corfu.el
index 4aadd75..b32f24d 100644
--- a/corfu.el
+++ b/corfu.el
@@ -465,36 +465,6 @@ 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 (replace-regexp-in-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 "\\(?:\\(?:\\`\\|/\\)\\.\\.?/\\|"
@@ -531,7 +501,6 @@ 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]