diff options
author | João Távora <joaotavora@gmail.com> | 2019-12-24 10:40:39 +0000 |
---|---|---|
committer | João Távora <joaotavora@gmail.com> | 2019-12-31 13:31:45 +0000 |
commit | b1c3ed9f328fccc04b80d2991a4f8d06ead186fb (patch) | |
tree | 535f601ba0711a2852fd1ad67aa14b2af7c4c1f2 /lisp/icomplete.el | |
parent | e3276f36c08691d6789b8eb49923735dc9565642 (diff) | |
download | emacs-b1c3ed9f328fccc04b80d2991a4f8d06ead186fb.tar.gz |
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.
(cherry picked from commit 0d2a711dc9a65dc8eb6e995369e70cddbcd7d9a4)
Diffstat (limited to 'lisp/icomplete.el')
-rw-r--r-- | lisp/icomplete.el | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/lisp/icomplete.el b/lisp/icomplete.el index bf7e2ea7cb4..ec5591d806e 100644 --- a/lisp/icomplete.el +++ b/lisp/icomplete.el @@ -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))) |