]> git.eshelyaron.com Git - emacs.git/commitdiff
Move flex style's minibuffer-default-aware sorting to lisp/icomplete.el
authorJoão Távora <joaotavora@gmail.com>
Tue, 24 Dec 2019 10:40:39 +0000 (10:40 +0000)
committerJoão Távora <joaotavora@gmail.com>
Tue, 31 Dec 2019 13:31:45 +0000 (13:31 +0000)
This moves the logic from the series of commits starting in the commit named:

  Improve sorting of flex completion style with non-nil minibuffer-default

to lisp/icomplete.el, so far the only confirmed beneficiary of that
functionality.

* lisp/icomplete.el (icomplete--sorted-completions): Consider
minibuffer-default here.

* lisp/minibuffer.el (completion--flex-adjust-metadata): Simplify.

(cherry picked from commit 0d2a711dc9a65dc8eb6e995369e70cddbcd7d9a4)

lisp/icomplete.el
lisp/minibuffer.el

index bf7e2ea7cb415e97e4a11bbe3e83873840cc22ad..ec5591d806e3202fe0fe39fd6c3796daa7e4e197 100644 (file)
@@ -446,19 +446,33 @@ Usually run by inclusion in `minibuffer-setup-hook'."
 (defun icomplete--sorted-completions ()
   (let ((all (completion-all-sorted-completions
               (icomplete--field-beg) (icomplete--field-end))))
-    (if (and fido-mode
-             (window-minibuffer-p)
-             (not minibuffer-default)
-             (eq (icomplete--category) 'file))
-        (cl-loop for l on all
-                 while (listp (cdr l))
-                 for comp = (cadr l)
-                 when (string= comp "./")
-                 do (setf (cdr l) (cddr l))
-                 and return
-                 (setq completion-all-sorted-completions (cons comp all))
-                 finally return all)
-      all)))
+    (cl-loop
+     for fn in (cond ((and minibuffer-default
+                           (= (icomplete--field-end) (icomplete--field-beg)))
+                      ;; When we have a non-nil default and no input
+                      ;; whatsoever: we want to make sure that default
+                      ;; is bubbled to the top so that
+                      ;; `icomplete-force-complete-and-exit' will
+                      ;; select it (do that even if the match doesn't
+                      ;; match the completion perfectly.
+                      `(,(lambda (comp)
+                           (equal minibuffer-default comp))
+                        ,(lambda (comp)
+                           (string-prefix-p minibuffer-default comp))))
+                     ((and fido-mode
+                           (not minibuffer-default)
+                           (eq (icomplete--category) 'file))
+                      `(,(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
+              (setq completion-all-sorted-completions (cons comp all)))
+     finally return all)))
 
 \f
 
index f900557296e41bf1b64b4868466f2a3637216a96..5ad51c0dd8a7bed6b4d47d02063654456a8b8244 100644 (file)
@@ -3596,9 +3596,10 @@ that is non-nil."
                   ;; JT@2019-12-23: FIXME: this is still wrong.  What
                   ;; we need to test here is "some input that actually
                   ;; leads to flex filtering", not "something after
-                  ;; the minibuffer prompt".  The latter is always
-                  ;; true for file searches, meaning the next clauses
-                  ;; will be ignored.
+                  ;; the minibuffer prompt".  Among other
+                  ;; inconsistencies, the latter is always true for
+                  ;; file searches, meaning the next clauses will be
+                  ;; ignored.
                   (> (point-max) (minibuffer-prompt-end)))
               (sort
                pre-sorted
@@ -3606,26 +3607,7 @@ that is non-nil."
                  (let ((s1 (get-text-property 0 'completion-score c1))
                        (s2 (get-text-property 0 'completion-score c2)))
                    (> (or s1 0) (or s2 0))))))
-             (minibuffer-default
-              ;; If we have an empty pattern and a non-nil default, we
-              ;; want to make sure that default is bubbled to the top
-              ;; so that a "force-completion" operation will select
-              ;; it.  We want that to happen even if it doesn't match
-              ;; the completion perfectly.
-              (cl-loop
-               ;; JT@2019-12-23: FIXME: ideally, we want to use
-               ;; flex-matching itself on the default itself, not
-               ;; `equal' or `string-prefix-p'.
-               for fn in '(equal string-prefix-p)
-               thereis (cl-loop
-                        for l on pre-sorted
-                        for comp = (cadr l)
-                        when (funcall fn minibuffer-default comp)
-                        do (setf (cdr l) (cddr l))
-                        and return (cons comp pre-sorted))
-               finally return pre-sorted))
-             (t
-              pre-sorted))))))
+             (t pre-sorted))))))
     `(metadata
       (display-sort-function
        . ,(compose-flex-sort-fn