Skip to content

Commit 0d2a711

Browse files
committed
Move flex style's minibuffer-default-aware sorting to lisp/icomplete.el
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.
1 parent a6b41a8 commit 0d2a711

File tree

2 files changed

+32
-36
lines changed

2 files changed

+32
-36
lines changed

lisp/icomplete.el

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -446,19 +446,33 @@ Usually run by inclusion in `minibuffer-setup-hook'."
446446
(defun icomplete--sorted-completions ()
447447
(let ((all (completion-all-sorted-completions
448448
(icomplete--field-beg) (icomplete--field-end))))
449-
(if (and fido-mode
450-
(window-minibuffer-p)
451-
(not minibuffer-default)
452-
(eq (icomplete--category) 'file))
453-
(cl-loop for l on all
454-
while (listp (cdr l))
455-
for comp = (cadr l)
456-
when (string= comp "./")
457-
do (setf (cdr l) (cddr l))
458-
and return
459-
(setq completion-all-sorted-completions (cons comp all))
460-
finally return all)
461-
all)))
449+
(cl-loop
450+
for fn in (cond ((and minibuffer-default
451+
(= (icomplete--field-end) (icomplete--field-beg)))
452+
;; When we have a non-nil default and no input
453+
;; whatsoever: we want to make sure that default
454+
;; is bubbled to the top so that
455+
;; `icomplete-force-complete-and-exit' will
456+
;; select it (do that even if the match doesn't
457+
;; match the completion perfectly.
458+
`(,(lambda (comp)
459+
(equal minibuffer-default comp))
460+
,(lambda (comp)
461+
(string-prefix-p minibuffer-default comp))))
462+
((and fido-mode
463+
(not minibuffer-default)
464+
(eq (icomplete--category) 'file))
465+
`(,(lambda (comp)
466+
(string= "./" comp)))))
467+
thereis (cl-loop
468+
for l on all
469+
while (consp (cdr l))
470+
for comp = (cadr l)
471+
when (funcall fn comp)
472+
do (setf (cdr l) (cddr l))
473+
and return
474+
(setq completion-all-sorted-completions (cons comp all)))
475+
finally return all)))
462476

463477

464478

lisp/minibuffer.el

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3596,36 +3596,18 @@ that is non-nil."
35963596
;; JT@2019-12-23: FIXME: this is still wrong. What
35973597
;; we need to test here is "some input that actually
35983598
;; leads to flex filtering", not "something after
3599-
;; the minibuffer prompt". The latter is always
3600-
;; true for file searches, meaning the next clauses
3601-
;; will be ignored.
3599+
;; the minibuffer prompt". Among other
3600+
;; inconsistencies, the latter is always true for
3601+
;; file searches, meaning the next clauses will be
3602+
;; ignored.
36023603
(> (point-max) (minibuffer-prompt-end)))
36033604
(sort
36043605
pre-sorted
36053606
(lambda (c1 c2)
36063607
(let ((s1 (get-text-property 0 'completion-score c1))
36073608
(s2 (get-text-property 0 'completion-score c2)))
36083609
(> (or s1 0) (or s2 0))))))
3609-
(minibuffer-default
3610-
;; If we have an empty pattern and a non-nil default, we
3611-
;; want to make sure that default is bubbled to the top
3612-
;; so that a "force-completion" operation will select
3613-
;; it. We want that to happen even if it doesn't match
3614-
;; the completion perfectly.
3615-
(cl-loop
3616-
;; JT@2019-12-23: FIXME: ideally, we want to use
3617-
;; flex-matching itself on the default itself, not
3618-
;; `equal' or `string-prefix-p'.
3619-
for fn in '(equal string-prefix-p)
3620-
thereis (cl-loop
3621-
for l on pre-sorted
3622-
for comp = (cadr l)
3623-
when (funcall fn minibuffer-default comp)
3624-
do (setf (cdr l) (cddr l))
3625-
and return (cons comp pre-sorted))
3626-
finally return pre-sorted))
3627-
(t
3628-
pre-sorted))))))
3610+
(t pre-sorted))))))
36293611
`(metadata
36303612
(display-sort-function
36313613
. ,(compose-flex-sort-fn

0 commit comments

Comments
 (0)