aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSpencer Baugh2025-09-03 08:48:05 -0400
committerJuri Linkov2025-10-16 20:18:23 +0300
commit17ac50ea9e105527753722b508ca44c58cbc892f (patch)
tree2f8ee078f06d7cab18fadec9ac13b2109d4dcb13
parentb0078bfa15029a2072bd762e32f472031700fe18 (diff)
downloademacs-17ac50ea9e105527753722b508ca44c58cbc892f.tar.gz
emacs-17ac50ea9e105527753722b508ca44c58cbc892f.zip
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.
-rw-r--r--lisp/minibuffer.el2
-rw-r--r--src/minibuf.c6
-rw-r--r--test/lisp/minibuffer-tests.el38
3 files changed, 38 insertions, 8 deletions
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index edc8e87fec0..4e4622fa7f9 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -4763,7 +4763,7 @@ the same set of elements."
4763 ;; `prefix' only wants to include the fixed part before the 4763 ;; `prefix' only wants to include the fixed part before the
4764 ;; wildcard, not the result of growing that fixed part. 4764 ;; wildcard, not the result of growing that fixed part.
4765 (when (seq-some (lambda (elem) (eq elem 'prefix)) wildcards) 4765 (when (seq-some (lambda (elem) (eq elem 'prefix)) wildcards)
4766 (setq prefix fixed)) 4766 (setq prefix (substring prefix 0 (length fixed))))
4767 (push prefix res) 4767 (push prefix res)
4768 ;; Push all the wildcards in this stretch, to preserve `point' and 4768 ;; Push all the wildcards in this stretch, to preserve `point' and
4769 ;; `star' wildcards before ELEM. 4769 ;; `star' wildcards before ELEM.
diff --git a/src/minibuf.c b/src/minibuf.c
index 6d96160a851..53bc905af6f 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -1820,12 +1820,6 @@ or from one of the possible completions. */)
1820 1820
1821 if (NILP (bestmatch)) 1821 if (NILP (bestmatch))
1822 return Qnil; /* No completions found. */ 1822 return Qnil; /* No completions found. */
1823 /* If we are ignoring case, and there is no exact match,
1824 and no additional text was supplied,
1825 don't change the case of what the user typed. */
1826 if (completion_ignore_case && bestmatchsize == SCHARS (string)
1827 && SCHARS (bestmatch) > bestmatchsize)
1828 return string;
1829 1823
1830 /* Return t if the supplied string is an exact match (counting case); 1824 /* Return t if the supplied string is an exact match (counting case);
1831 it does not require any change to be made. */ 1825 it does not require any change to be made. */
diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el
index 03e8ea24018..c7b24a4928d 100644
--- a/test/lisp/minibuffer-tests.el
+++ b/test/lisp/minibuffer-tests.el
@@ -345,7 +345,34 @@
345 (should (equal 345 (should (equal
346 (let ((completion-ignore-case t)) 346 (let ((completion-ignore-case t))
347 (completion-pcm-try-completion "a" '("ABC" "ABD") nil 1)) 347 (completion-pcm-try-completion "a" '("ABC" "ABD") nil 1))
348 '("AB" . 2)))) 348 '("AB" . 2)))
349 ;; Even when the text isn't growing.
350 (should (equal
351 (let ((completion-ignore-case t))
352 (completion-pcm-try-completion "ab" '("ABC" "ABD") nil 2))
353 '("AB" . 2)))
354 ;; Or when point is in the middle of the region changing case.
355 (should (equal
356 (let ((completion-ignore-case t))
357 (completion-pcm-try-completion "ab" '("ABC" "ABD") nil 1))
358 '("AB" . 2)))
359 ;; Even when the existing minibuffer contents has mixed case.
360 (should (equal
361 (let ((completion-ignore-case t))
362 (completion-pcm-try-completion "Ab" '("ABC" "ABD") nil 1))
363 '("AB" . 2)))
364 ;; But not if the completions don't actually all have the same case.
365 (should (equal
366 (let ((completion-ignore-case t))
367 (completion-pcm-try-completion "Ab" '("abc" "ABD") nil 1))
368 '("Ab" . 2)))
369 ;; We don't change case if it doesn't match all of the completions, though.
370 (should (equal
371 (let ((completion-ignore-case t)) (try-completion "a" '("ax" "Ay")))
372 "a"))
373 (should (equal
374 (let ((completion-ignore-case t)) (try-completion "a" '("Ay" "ax")))
375 "a")))
349 376
350(ert-deftest completion-substring-test-1 () 377(ert-deftest completion-substring-test-1 ()
351 ;; One third of a match! 378 ;; One third of a match!
@@ -409,6 +436,15 @@
409 (should (equal 436 (should (equal
410 (completion-pcm--merge-try '("a" prefix "b") '("axb" "ayb") "" "") 437 (completion-pcm--merge-try '("a" prefix "b") '("axb" "ayb") "" "")
411 '("ab" . 2))) 438 '("ab" . 2)))
439 ;; Letter-casing from the completions on the common prefix is still applied.
440 (should (equal
441 (let ((completion-ignore-case t))
442 (completion-pcm--merge-try '("a" prefix "b") '("Axb" "Ayb") "" ""))
443 '("Ab" . 2)))
444 (should (equal
445 (let ((completion-ignore-case t))
446 (completion-pcm--merge-try '("a" prefix "b") '("AAxb" "AAyb") "" ""))
447 '("Ab" . 2)))
412 ;; substring completion should successfully complete the entire string 448 ;; substring completion should successfully complete the entire string
413 (should (equal 449 (should (equal
414 (completion-substring-try-completion "b" '("ab" "ab") nil 0) 450 (completion-substring-try-completion "b" '("ab" "ab") nil 0)