From: Dmitry Gutov Date: Sun, 23 Nov 2014 03:36:15 +0000 (+0200) Subject: company-update-candidates: Don't be fooled by a few prefix completions X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/abf95f731b3184431602db3e760364553b9d0782 company-update-candidates: Don't be fooled by a few prefix completions ...among non-prefix ones. Obsoletes https://github.com/abingham/emacs-ycmd/pull/92. `company-complete-common' was likewise too eager; this fixes it. --- diff --git a/company-tests.el b/company-tests.el index 26e98e2a9..08b846388 100644 --- a/company-tests.el +++ b/company-tests.el @@ -90,6 +90,20 @@ (should (eq t (company--good-prefix-p "abc"))) (should (eq t (company--good-prefix-p '("bar" . t))))))) +(ert-deftest company-common-with-non-prefix-completion () + (let ((company-backend #'ignore) + (company-prefix "abc") + company-candidates + company-candidates-length + company-candidates-cache + company-common) + (company-update-candidates '("abc" "def-abc")) + (should (null company-common)) + (company-update-candidates '("abc" "abe-c")) + (should (null company-common)) + (company-update-candidates '("abcd" "abcde" "abcdf")) + (should (equal "abcd" company-common)))) + (ert-deftest company-multi-backend-with-lambdas () (let ((company-backend (list (lambda (command &optional arg &rest ignore) diff --git a/company.el b/company.el index a44f1507b..6ad5c66dc 100644 --- a/company.el +++ b/company.el @@ -1084,14 +1084,11 @@ can retrieve meta-data for them." ;; We want to support non-prefix completion, so filtering is the ;; responsibility of each respective backend, not ours. ;; On the other hand, we don't want to replace non-prefix input in - ;; `company-complete-common'. + ;; `company-complete-common', unless it's the sole candidate. (setq company-common (if (cdr company-candidates) - (let ((common (try-completion company-prefix company-candidates))) - (if (eq common t) - ;; Mulple equal strings, probably with different - ;; annotations. - company-prefix + (let ((common (try-completion "" company-candidates))) + (when (string-prefix-p company-prefix common) common)) (car company-candidates)))))