aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSpencer Baugh2024-08-26 10:12:51 -0400
committerEli Zaretskii2024-09-14 12:24:08 +0300
commit3cda1fdc3b755dd329617cabc266e2b86894d0cb (patch)
tree4e575f4fdbacb5a47f351a418fc21e94cdd33958
parent57d93d0259a3cc9a180b1bcb3cec3f670485f82c (diff)
downloademacs-3cda1fdc3b755dd329617cabc266e2b86894d0cb.tar.gz
emacs-3cda1fdc3b755dd329617cabc266e2b86894d0cb.zip
Correctly include fixed strings before a prefix wildcard in PCM
In 03ac16ece40ba3e3ba805d6a61cc457d84bf3792 I fixed a bug with the PCM implementation of substring completion, relating to the handling of PCM wildcards. However, this fix was incomplete. This change completes the fix by also including a fixed string if it appears before a 'prefix' wildcard, even if 'try-completion' doesn't discover that fixed string grows to a unique completion. I discovered this bug while working on enhancements to PCM completion related to 'completion-pcm-leading-wildcard'. * lisp/minibuffer.el (completion-pcm--merge-completions): Include fixed strings before 'prefix wildcard. (Bug#72819) * test/lisp/minibuffer-tests.el (completion-substring-test-5): Add a test for this behavior.
-rw-r--r--lisp/minibuffer.el15
-rw-r--r--test/lisp/minibuffer-tests.el17
2 files changed, 21 insertions, 11 deletions
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index bef565378ea..216385d9cdf 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -4384,18 +4384,21 @@ the same set of elements."
4384 (unique (or (and (eq prefix t) (setq prefix fixed)) 4384 (unique (or (and (eq prefix t) (setq prefix fixed))
4385 (and (stringp prefix) 4385 (and (stringp prefix)
4386 (eq t (try-completion prefix comps)))))) 4386 (eq t (try-completion prefix comps))))))
4387 ;; if the common prefix is unique, it also is a common
4388 ;; suffix, so we should add it for `prefix' elements
4389 (unless (or (and (eq elem 'prefix) (not unique))
4390 (equal prefix ""))
4391 (push prefix res))
4392 ;; If there's only one completion, `elem' is not useful 4387 ;; If there's only one completion, `elem' is not useful
4393 ;; any more: it can only match the empty string. 4388 ;; any more: it can only match the empty string.
4394 ;; FIXME: in some cases, it may be necessary to turn an 4389 ;; FIXME: in some cases, it may be necessary to turn an
4395 ;; `any' into a `star' because the surrounding context has 4390 ;; `any' into a `star' because the surrounding context has
4396 ;; changed such that string->pattern wouldn't add an `any' 4391 ;; changed such that string->pattern wouldn't add an `any'
4397 ;; here any more. 4392 ;; here any more.
4398 (unless unique 4393 (if unique
4394 ;; if the common prefix is unique, it also is a common
4395 ;; suffix, so we should add it for `prefix' elements
4396 (push prefix res)
4397 ;; `prefix' only wants to include the fixed part before the
4398 ;; wildcard, not the result of growing that fixed part.
4399 (when (eq elem 'prefix)
4400 (setq prefix fixed))
4401 (push prefix res)
4399 (push elem res) 4402 (push elem res)
4400 ;; Extract common suffix additionally to common prefix. 4403 ;; Extract common suffix additionally to common prefix.
4401 ;; Don't do it for `any' since it could lead to a merged 4404 ;; Don't do it for `any' since it could lead to a merged
diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el
index df36bce4634..38c2b8c4552 100644
--- a/test/lisp/minibuffer-tests.el
+++ b/test/lisp/minibuffer-tests.el
@@ -306,13 +306,20 @@
306 6))) 306 6)))
307 307
308(ert-deftest completion-substring-test-5 () 308(ert-deftest completion-substring-test-5 ()
309 ;; merge-completions needs to work correctly when 309 ;; Normally a `prefix' wildcard ignores the common prefix to its
310 ;; left, since it only grows the common suffix; but if that common
311 ;; prefix is also a common suffix, it should be included.
310 (should (equal 312 (should (equal
311 (completion-pcm--merge-completions '("ab" "sab") '(prefix "b")) 313 (completion-pcm--merge-try '(prefix "b") '("ab" "sab") "" "")
312 '("b" "a" prefix))) 314 '("ab" . 2)))
313 (should (equal 315 (should (equal
314 (completion-pcm--merge-completions '("ab" "ab") '(prefix "b")) 316 (completion-pcm--merge-try '(prefix "b") '("ab" "ab") "" "")
315 '("b" "a"))) 317 '("ab" . 2)))
318 ;; When there's a fixed string before `prefix', that fixed string
319 ;; should always be included.
320 (should (equal
321 (completion-pcm--merge-try '("a" prefix "b") '("axb" "ayb") "" "")
322 '("ab" . 2)))
316 ;; substring completion should successfully complete the entire string 323 ;; substring completion should successfully complete the entire string
317 (should (equal 324 (should (equal
318 (completion-substring-try-completion "b" '("ab" "ab") nil 0) 325 (completion-substring-try-completion "b" '("ab" "ab") nil 0)