master 374a2a2b895: pcm-try-completion: Move point to the last non-empty wildcard
Sean Whitton <[email protected]>
| Newsgroups | gmane.emacs.diffs |
|---|---|
| Message-ID | <[email protected]> |
branch: master commit 374a2a2b895141f4de07b74a9ff6d043d0b4efb0 Author: Spencer Baugh <[email protected]> Commit: Sean Whitton <[email protected]> pcm-try-completion: Move point to the last non-empty wildcard completion-pcm-try-completion always moved point to the last wildcard in the string which could still be expanded to match a completion. However, if the desired completion has an empty string at the site of that wildcard, there's nothing the user could usefully type to continue completion there. So, it's better to move point to last wildcard where all the possible completions have non-empty text, if there is such a wildcard. * lisp/minibuffer.el (completion-pcm--string->pattern): Don't replace 'any-delim with 'prefix when completion-pcm-leading-wildcard is non-nil: too aggressive. (completion-pcm--merge-completions): Push 'nonempty' when all completions are nonempty at this wildcard (bug#81629). (completion-pcm--merge-try): Move point to the last 'nonempty'. * test/lisp/minibuffer-tests.el (completion-pcm-test-anydelim) (completion-substring-test-5): Update for new behavior. --- lisp/minibuffer.el | 7 ++++++- test/lisp/minibuffer-tests.el | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 919e257ef7a..c9f5c6a538f 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -4404,7 +4404,7 @@ or a symbol, see `completion-pcm--merge-completions'." (setq p0 p) (push (substring string p (match-end 0)) pattern) ;; `any-delim' is used so that "a-b" also finds "array->beginning". - (setq pending (if completion-pcm-leading-wildcard 'prefix 'any-delim)) + (setq pending 'any-delim) (setq p0 (match-end 0)))) (setq p p0)) @@ -4813,6 +4813,10 @@ the same set of elements." (when (seq-some (lambda (elem) (eq elem 'prefix)) wildcards) (setq prefix (substring prefix 0 (length fixed)))) (push prefix res) + (when (seq-every-p (lambda (comp) (< (length prefix) (length comp))) comps) + ;; Wherever the user could type a character to disambiguate between + ;; completions, possibly move point there. + (push 'nonempty res)) ;; Push all the wildcards in this stretch, to preserve `point' and ;; `star' wildcards before ELEM. Collapse multiple `star's down to one ;; on each side of point. (bug#81394) @@ -4892,6 +4896,7 @@ the same set of elements." ;; the last place where there's something to choose, or ;; at the very end. (pointpat (or (memq 'point mergedpat) + (memq 'nonempty mergedpat) (memq 'any mergedpat) (memq 'star mergedpat) ;; Not `prefix'. diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el index 2f70d248711..697eaf1d751 100644 --- a/test/lisp/minibuffer-tests.el +++ b/test/lisp/minibuffer-tests.el @@ -371,7 +371,7 @@ ;; sequence of delimiters. (should (equal (completion-pcm-try-completion "-x" '("-_.x" "-__x") nil 2) - '("-_x" . 3)))) + '("-_x" . 2)))) (ert-deftest completion-pcm-test-pattern->regex () (should (equal (completion-pcm--pattern->regex @@ -474,7 +474,7 @@ ;; prefix is also a common suffix, it should be included. (should (equal (completion-pcm--merge-try '(prefix "b") '("ab" "sab") "" "") - '("ab" . 2))) + '("ab" . 0))) (should (equal (completion-pcm--merge-try '(prefix "b") '("ab" "ab") "" "") '("ab" . 2))) @@ -482,16 +482,16 @@ ;; should always be included. (should (equal (completion-pcm--merge-try '("a" prefix "b") '("axb" "ayb") "" "") - '("ab" . 2))) + '("ab" . 1))) ;; Letter-casing from the completions on the common prefix is still applied. (should (equal (let ((completion-ignore-case t)) (completion-pcm--merge-try '("a" prefix "b") '("Axb" "Ayb") "" "")) - '("Ab" . 2))) + '("Ab" . 1))) (should (equal (let ((completion-ignore-case t)) (completion-pcm--merge-try '("a" prefix "b") '("AAxb" "AAyb") "" "")) - '("Ab" . 2))) + '("Ab" . 1))) ;; substring completion should successfully complete the entire string (should (equal (completion-substring-try-completion "b" '("ab" "ab") nil 0)