]> git.eshelyaron.com Git - emacs.git/commitdiff
Don't resort Icomplete candidates when default already on top
authorJoão Távora <joaotavora@gmail.com>
Sun, 6 Sep 2020 07:35:53 +0000 (08:35 +0100)
committerJoão Távora <joaotavora@gmail.com>
Sun, 6 Sep 2020 07:36:39 +0000 (08:36 +0100)
Fixes: bug#43222
Icomplete mode re-sorts candidates, bubbling the default to top if
it's found somewhere down the list.  This is done according to two
criteria: exact match and prefix match.  Before this fix, it didn't
take into account the possibility that the exact match for the default
would already be on top, and would incorrectly bubble a prefixing
completion down the list to the top.  This commit fixes that.

* lisp/icomplete.el (icomplete--sorted-completions):
Rework. Recomment.

lisp/icomplete.el

index ba266cfbfe9e5675dbd2b165a3c48dc910b4d2fa..47d78a0bc82882864fd4b71cac2092601dc82afc 100644 (file)
@@ -469,6 +469,7 @@ Usually run by inclusion in `minibuffer-setup-hook'."
        with beg = (icomplete--field-beg)
        with end = (icomplete--field-end)
        with all = (completion-all-sorted-completions beg end)
+       ;; First, establish the "bubble up" predicates.
        for fn in (cond ((and minibuffer-default
                              (stringp minibuffer-default) ; bug#38992
                              (= (icomplete--field-end) (icomplete--field-beg)))
@@ -493,14 +494,18 @@ Usually run by inclusion in `minibuffer-setup-hook'."
                         ;; what vanilla Emacs and `ido-mode' both do.
                         `(,(lambda (comp)
                              (string= "./" comp)))))
-       thereis (cl-loop
-                for l on all
-                while (consp (cdr l))
-                for comp = (cadr l)
-                when (funcall fn comp)
-                do (setf (cdr l) (cddr l))
-                and return
-                (completion--cache-all-sorted-completions beg end (cons comp all)))
+       ;; Now, look for a completion matching one of those predicates
+       ;; to bubble up (unless that completion is already on top).
+       thereis (or
+                (and (funcall fn (car all)) all)
+                (cl-loop
+                 for l on all
+                 while (consp (cdr l))
+                 for comp = (cadr l)
+                 when (funcall fn comp)
+                 do (setf (cdr l) (cddr l))
+                 and return
+                 (completion--cache-all-sorted-completions beg end (cons comp all))))
        finally return all)))
 
 \f