diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 5d7cbcedd41..52a286018a1 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -4025,7 +4025,9 @@ the same set of elements." (unique (or (and (eq prefix t) (setq prefix fixed)) (and (stringp prefix) (eq t (try-completion prefix comps)))))) - (unless (or (eq elem 'prefix) + ;; if the common prefix is unique, it also is a common + ;; suffix, so we should add it for `prefix' elements + (unless (or (and (eq elem 'prefix) (not unique)) (equal prefix "")) (push prefix res)) ;; If there's only one completion, `elem' is not useful diff --git a/test/lisp/minibuffer-tests.el b/test/lisp/minibuffer-tests.el index ff58d35eb3e..4f92d7f841c 100644 --- a/test/lisp/minibuffer-tests.el +++ b/test/lisp/minibuffer-tests.el @@ -298,6 +298,19 @@ "jab" '("dabjabstabby" "many") nil 3))) 6))) +(ert-deftest completion-substring-test-5 () + ;; merge-completions needs to work correctly when + (should (equal + (completion-pcm--merge-completions '("ab" "sab") '(prefix "b")) + '("b" "a" prefix))) + (should (equal + (completion-pcm--merge-completions '("ab" "ab") '(prefix "b")) + '("b" "a"))) + ;; substring completion should successfully complete the entire string + (should (equal + (completion-substring-try-completion "b" '("ab" "ab") nil 0) + '("ab" . 2)))) + (ert-deftest completion-flex-test-1 () ;; Fuzzy match (should (equal