diff options
| author | João Távora | 2019-12-22 22:51:08 +0100 |
|---|---|---|
| committer | João Távora | 2019-12-22 22:57:16 +0100 |
| commit | df3fe4e275205adbf57833552f6899d4810450fe (patch) | |
| tree | 5792d0faa8be4c02b964cb63ea989dd48a89352b | |
| parent | 7b3b27eef1325b41187f2e9cc898644d5eae9ff3 (diff) | |
| download | emacs-df3fe4e275205adbf57833552f6899d4810450fe.tar.gz emacs-df3fe4e275205adbf57833552f6899d4810450fe.zip | |
Fix bug in flex completion style's sorting and simplify
This previous commit targetting this function introduced a bug whereby
the completion table's sorting function wouldn't be called. That is
fixed by this commit, which also simplifies the function further: it
now skips re-sorting the completions completely if there is no
minibuffer input at all (in other words, when flex isn't doing
anything useful).
* lisp/minibuffer.el (completion--flex-adjust-metadata): Simplify.
| -rw-r--r-- | lisp/minibuffer.el | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index c0df383e288..2dba26818e1 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -3583,36 +3583,38 @@ that is non-nil." | |||
| 3583 | (put 'flex 'completion--adjust-metadata 'completion--flex-adjust-metadata) | 3583 | (put 'flex 'completion--adjust-metadata 'completion--flex-adjust-metadata) |
| 3584 | 3584 | ||
| 3585 | (defun completion--flex-adjust-metadata (metadata) | 3585 | (defun completion--flex-adjust-metadata (metadata) |
| 3586 | (cl-flet ((compose-flex-sort-fn | 3586 | (cl-flet |
| 3587 | (existing-sort-fn) ; wish `cl-flet' had proper indentation... | 3587 | ((compose-flex-sort-fn |
| 3588 | (lambda (completions) | 3588 | (existing-sort-fn) ; wish `cl-flet' had proper indentation... |
| 3589 | (let* ((by-score | 3589 | (lambda (completions) |
| 3590 | (sort | 3590 | (let ((pre-sorted |
| 3591 | (if existing-sort-fn | 3591 | (if existing-sort-fn |
| 3592 | (funcall existing-sort-fn completions) | 3592 | (funcall existing-sort-fn completions) |
| 3593 | completions) | 3593 | completions))) |
| 3594 | (lambda (c1 c2) | 3594 | (cond |
| 3595 | (let ((s1 (get-text-property 0 'completion-score c1)) | 3595 | ((or (not (window-minibuffer-p)) |
| 3596 | (s2 (get-text-property 0 'completion-score c2))) | 3596 | (> (point-max) |
| 3597 | (> (or s1 0) (or s2 0)))))) | 3597 | (minibuffer-prompt-end))) |
| 3598 | (promoted-default | 3598 | (sort |
| 3599 | (and minibuffer-default | 3599 | pre-sorted |
| 3600 | (and (window-minibuffer-p) | 3600 | (lambda (c1 c2) |
| 3601 | (= (point-max) | 3601 | (let ((s1 (get-text-property 0 'completion-score c1)) |
| 3602 | (minibuffer-prompt-end))) | 3602 | (s2 (get-text-property 0 'completion-score c2))) |
| 3603 | ;; If we have an empty pattern and a | 3603 | (> (or s1 0) (or s2 0)))))) |
| 3604 | ;; non-nil default we probably want to | 3604 | (minibuffer-default |
| 3605 | ;; make sure that default is bubbled to | 3605 | ;; If we have an empty pattern and a non-nil default, we |
| 3606 | ;; the top even if it doesn't match the | 3606 | ;; probably want to make sure that default is bubbled to |
| 3607 | ;; completion perfectly (like in M-x man | 3607 | ;; the top so that a "force-completion" operation will |
| 3608 | ;; case) | 3608 | ;; select it. We want that to happen even if it doesn't |
| 3609 | (cl-loop | 3609 | ;; match the completion perfectly. |
| 3610 | for l on by-score | 3610 | (cl-loop |
| 3611 | for comp = (cadr l) | 3611 | for l on pre-sorted |
| 3612 | when (string-prefix-p minibuffer-default comp) | 3612 | for comp = (cadr l) |
| 3613 | do (setf (cdr l) (cddr l)) | 3613 | when (string-prefix-p minibuffer-default comp) |
| 3614 | and return (cons comp by-score))))) | 3614 | do (setf (cdr l) (cddr l)) |
| 3615 | (or promoted-default by-score))))) | 3615 | and return (cons comp pre-sorted))) |
| 3616 | (t | ||
| 3617 | pre-sorted)))))) | ||
| 3616 | `(metadata | 3618 | `(metadata |
| 3617 | (display-sort-function | 3619 | (display-sort-function |
| 3618 | . ,(compose-flex-sort-fn | 3620 | . ,(compose-flex-sort-fn |