diff options
| author | João Távora | 2019-12-24 10:40:39 +0000 |
|---|---|---|
| committer | João Távora | 2019-12-31 13:31:45 +0000 |
| commit | b1c3ed9f328fccc04b80d2991a4f8d06ead186fb (patch) | |
| tree | 535f601ba0711a2852fd1ad67aa14b2af7c4c1f2 | |
| parent | e3276f36c08691d6789b8eb49923735dc9565642 (diff) | |
| download | emacs-b1c3ed9f328fccc04b80d2991a4f8d06ead186fb.tar.gz emacs-b1c3ed9f328fccc04b80d2991a4f8d06ead186fb.zip | |
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)
| -rw-r--r-- | lisp/icomplete.el | 40 | ||||
| -rw-r--r-- | lisp/minibuffer.el | 28 |
2 files changed, 32 insertions, 36 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'." | |||
| 446 | (defun icomplete--sorted-completions () | 446 | (defun icomplete--sorted-completions () |
| 447 | (let ((all (completion-all-sorted-completions | 447 | (let ((all (completion-all-sorted-completions |
| 448 | (icomplete--field-beg) (icomplete--field-end)))) | 448 | (icomplete--field-beg) (icomplete--field-end)))) |
| 449 | (if (and fido-mode | 449 | (cl-loop |
| 450 | (window-minibuffer-p) | 450 | for fn in (cond ((and minibuffer-default |
| 451 | (not minibuffer-default) | 451 | (= (icomplete--field-end) (icomplete--field-beg))) |
| 452 | (eq (icomplete--category) 'file)) | 452 | ;; When we have a non-nil default and no input |
| 453 | (cl-loop for l on all | 453 | ;; whatsoever: we want to make sure that default |
| 454 | while (listp (cdr l)) | 454 | ;; is bubbled to the top so that |
| 455 | for comp = (cadr l) | 455 | ;; `icomplete-force-complete-and-exit' will |
| 456 | when (string= comp "./") | 456 | ;; select it (do that even if the match doesn't |
| 457 | do (setf (cdr l) (cddr l)) | 457 | ;; match the completion perfectly. |
| 458 | and return | 458 | `(,(lambda (comp) |
| 459 | (setq completion-all-sorted-completions (cons comp all)) | 459 | (equal minibuffer-default comp)) |
| 460 | finally return all) | 460 | ,(lambda (comp) |
| 461 | all))) | 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))) | ||
| 462 | 476 | ||
| 463 | 477 | ||
| 464 | 478 | ||
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index f900557296e..5ad51c0dd8a 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -3596,9 +3596,10 @@ that is non-nil." | |||
| 3596 | ;; JT@2019-12-23: FIXME: this is still wrong. What | 3596 | ;; JT@2019-12-23: FIXME: this is still wrong. What |
| 3597 | ;; we need to test here is "some input that actually | 3597 | ;; we need to test here is "some input that actually |
| 3598 | ;; leads to flex filtering", not "something after | 3598 | ;; leads to flex filtering", not "something after |
| 3599 | ;; the minibuffer prompt". The latter is always | 3599 | ;; the minibuffer prompt". Among other |
| 3600 | ;; true for file searches, meaning the next clauses | 3600 | ;; inconsistencies, the latter is always true for |
| 3601 | ;; will be ignored. | 3601 | ;; file searches, meaning the next clauses will be |
| 3602 | ;; ignored. | ||
| 3602 | (> (point-max) (minibuffer-prompt-end))) | 3603 | (> (point-max) (minibuffer-prompt-end))) |
| 3603 | (sort | 3604 | (sort |
| 3604 | pre-sorted | 3605 | pre-sorted |
| @@ -3606,26 +3607,7 @@ that is non-nil." | |||
| 3606 | (let ((s1 (get-text-property 0 'completion-score c1)) | 3607 | (let ((s1 (get-text-property 0 'completion-score c1)) |
| 3607 | (s2 (get-text-property 0 'completion-score c2))) | 3608 | (s2 (get-text-property 0 'completion-score c2))) |
| 3608 | (> (or s1 0) (or s2 0)))))) | 3609 | (> (or s1 0) (or s2 0)))))) |
| 3609 | (minibuffer-default | 3610 | (t pre-sorted)))))) |
| 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)))))) | ||
| 3629 | `(metadata | 3611 | `(metadata |
| 3630 | (display-sort-function | 3612 | (display-sort-function |
| 3631 | . ,(compose-flex-sort-fn | 3613 | . ,(compose-flex-sort-fn |