emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master abf95f7 19/66: company-update-candidates: Don't be fooled


From: Dmitry Gutov
Subject: [elpa] master abf95f7 19/66: company-update-candidates: Don't be fooled by a few prefix completions
Date: Tue, 13 Jan 2015 02:44:49 +0000

branch: master
commit abf95f731b3184431602db3e760364553b9d0782
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    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.
---
 company-tests.el |   14 ++++++++++++++
 company.el       |    9 +++------
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/company-tests.el b/company-tests.el
index 26e98e2..08b8463 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 a44f150..6ad5c66 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)))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]