mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-05 22:20:24 -08:00
Return case common to all completions in try-completion
When completion-ignore-case is non-nil, if all completions share a common prefix ignoring case, try-completion has always returned that. Now, if all completions also share a common prefix including case, try-completion includes that common prefix in its return value (bug#79377). * lisp/minibuffer.el (completion-pcm--merge-completions): Always use return value from try-completion, which may change case. * src/minibuf.c (Ftry_completion): Return the common prefix which changes case. * test/lisp/minibuffer-tests.el (completion-pcm-bug4219) (completion-substring-test-5): New tests.
This commit is contained in:
parent
b0078bfa15
commit
17ac50ea9e
3 changed files with 38 additions and 8 deletions
|
|
@ -4763,7 +4763,7 @@ the same set of elements."
|
|||
;; `prefix' only wants to include the fixed part before the
|
||||
;; wildcard, not the result of growing that fixed part.
|
||||
(when (seq-some (lambda (elem) (eq elem 'prefix)) wildcards)
|
||||
(setq prefix fixed))
|
||||
(setq prefix (substring prefix 0 (length fixed))))
|
||||
(push prefix res)
|
||||
;; Push all the wildcards in this stretch, to preserve `point' and
|
||||
;; `star' wildcards before ELEM.
|
||||
|
|
|
|||
|
|
@ -1820,12 +1820,6 @@ or from one of the possible completions. */)
|
|||
|
||||
if (NILP (bestmatch))
|
||||
return Qnil; /* No completions found. */
|
||||
/* If we are ignoring case, and there is no exact match,
|
||||
and no additional text was supplied,
|
||||
don't change the case of what the user typed. */
|
||||
if (completion_ignore_case && bestmatchsize == SCHARS (string)
|
||||
&& SCHARS (bestmatch) > bestmatchsize)
|
||||
return string;
|
||||
|
||||
/* Return t if the supplied string is an exact match (counting case);
|
||||
it does not require any change to be made. */
|
||||
|
|
|
|||
|
|
@ -345,7 +345,34 @@
|
|||
(should (equal
|
||||
(let ((completion-ignore-case t))
|
||||
(completion-pcm-try-completion "a" '("ABC" "ABD") nil 1))
|
||||
'("AB" . 2))))
|
||||
'("AB" . 2)))
|
||||
;; Even when the text isn't growing.
|
||||
(should (equal
|
||||
(let ((completion-ignore-case t))
|
||||
(completion-pcm-try-completion "ab" '("ABC" "ABD") nil 2))
|
||||
'("AB" . 2)))
|
||||
;; Or when point is in the middle of the region changing case.
|
||||
(should (equal
|
||||
(let ((completion-ignore-case t))
|
||||
(completion-pcm-try-completion "ab" '("ABC" "ABD") nil 1))
|
||||
'("AB" . 2)))
|
||||
;; Even when the existing minibuffer contents has mixed case.
|
||||
(should (equal
|
||||
(let ((completion-ignore-case t))
|
||||
(completion-pcm-try-completion "Ab" '("ABC" "ABD") nil 1))
|
||||
'("AB" . 2)))
|
||||
;; But not if the completions don't actually all have the same case.
|
||||
(should (equal
|
||||
(let ((completion-ignore-case t))
|
||||
(completion-pcm-try-completion "Ab" '("abc" "ABD") nil 1))
|
||||
'("Ab" . 2)))
|
||||
;; We don't change case if it doesn't match all of the completions, though.
|
||||
(should (equal
|
||||
(let ((completion-ignore-case t)) (try-completion "a" '("ax" "Ay")))
|
||||
"a"))
|
||||
(should (equal
|
||||
(let ((completion-ignore-case t)) (try-completion "a" '("Ay" "ax")))
|
||||
"a")))
|
||||
|
||||
(ert-deftest completion-substring-test-1 ()
|
||||
;; One third of a match!
|
||||
|
|
@ -409,6 +436,15 @@
|
|||
(should (equal
|
||||
(completion-pcm--merge-try '("a" prefix "b") '("axb" "ayb") "" "")
|
||||
'("ab" . 2)))
|
||||
;; 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)))
|
||||
(should (equal
|
||||
(let ((completion-ignore-case t))
|
||||
(completion-pcm--merge-try '("a" prefix "b") '("AAxb" "AAyb") "" ""))
|
||||
'("Ab" . 2)))
|
||||
;; substring completion should successfully complete the entire string
|
||||
(should (equal
|
||||
(completion-substring-try-completion "b" '("ab" "ab") nil 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue