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

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

[elpa] externals/corfu cca1eaf 09/14: Extract corfu--move-prefix-candida


From: Protesilaos Stavrou
Subject: [elpa] externals/corfu cca1eaf 09/14: Extract corfu--move-prefix-candidates-to-front
Date: Sat, 17 Apr 2021 10:25:43 -0400 (EDT)

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

    Extract corfu--move-prefix-candidates-to-front
---
 corfu.el | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/corfu.el b/corfu.el
index f71ec4e..cf45558 100644
--- a/corfu.el
+++ b/corfu.el
@@ -287,6 +287,12 @@ If `line-spacing/=nil' or in text-mode, the background 
color is used instead.")
         (lambda (x) (and (not (string-match-p ignore x)) (funcall pred x)))
       (lambda (x) (not (string-match-p ignore x))))))
 
+(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)))
+    (nconc (seq-filter (lambda (x) (string-prefix-p word x)) candidates)
+           (seq-remove (lambda (x) (string-prefix-p word x)) candidates))))
+
 (defun corfu--recompute-candidates (str bounds metadata pt table pred)
   "Recompute candidates from STR, BOUNDS, METADATA, PT, TABLE and PRED."
   (let* ((field (substring str (car bounds) (+ pt (cdr bounds))))
@@ -301,11 +307,7 @@ If `line-spacing/=nil' or in text-mode, the background 
color is used instead.")
     (setq all (if-let (sort (corfu--metadata-get metadata 
'display-sort-function))
                   (funcall sort all)
                 (sort all #'corfu--sort-predicate)))
-    ;; Move candidates which match prefix to the beginning
-    (let* ((word (replace-regexp-in-string " .*" "" field))
-           (prefix (seq-filter (lambda (x) (string-prefix-p word x)) all))
-           (not-prefix (seq-remove (lambda (x) (string-prefix-p word x)) all)))
-      (setq all (nconc prefix not-prefix)))
+    (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]