]> code.delx.au - gnu-emacs-elpa/commitdiff
company-calculate-candidates: Instead of company-candidates, use candidates
authorDmitry Gutov <dgutov@yandex.ru>
Sun, 24 Mar 2013 22:03:55 +0000 (02:03 +0400)
committerDmitry Gutov <dgutov@yandex.ru>
Sun, 24 Mar 2013 22:03:55 +0000 (02:03 +0400)
NEWS.md
company-tests.el
company.el

diff --git a/NEWS.md b/NEWS.md
index e05f1097f01164d0507f60c83208e7de2d197351..fc1ffc27c10728005fb994b73076304391722ced 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,9 @@
 # History of user-visible changes
 
+## Next
+
+* Fixed `company-require-match` mechanics.
+
 ## 2013-03-24 (0.6.2)
 
 * `global-company-mode` is now autoloaded.
index 84b35037e08b7d0f294f445b7c52a65c4be3d970..fd89b58ece793db75a8ee8b5f8cc84bd7f3262d3 100644 (file)
     (company-mode)
     (should-error
      (company-begin-backend (lambda (command &rest ignore))))
-    (let ((company-backends
+    (let (company-frontends
+          (company-backends
            (list (lambda (command &optional arg)
                    (case command
                      (prefix "a")
                      (candidates '("a" "ab" "ac")))))))
-      (company-complete)
-      (setq this-command 'company-complete)
+      (let (this-command)
+        (company-complete))
+      (company-post-command)
       (should (eq 3 company-candidates-length)))))
+
+(ert-deftest company-require-match-explicit ()
+  (with-temp-buffer
+    (insert "ab")
+    (company-mode)
+    (let (company-frontends
+          (company-require-match 'company-explicit-action-p)
+          (company-backends
+           (list (lambda (command &optional arg)
+                   (case command
+                     (prefix (buffer-substring (point-min) (point)))
+                     (candidates '("abc" "abd")))))))
+      (let (this-command)
+        (company-complete))
+      (let ((last-command-event ?e))
+        (self-insert-command 1))
+      (company-post-command)
+      (should (eq 2 company-candidates-length))
+      (should (eq 3 (point))))))
+
+(ert-deftest company-dont-require-match-idle ()
+  (with-temp-buffer
+    (insert "ab")
+    (company-mode)
+    (let (company-frontends
+          (company-require-match 'company-explicit-action-p)
+          (company-backends
+           (list (lambda (command &optional arg)
+                   (case command
+                     (prefix (buffer-substring (point-min) (point)))
+                     (candidates '("abc" "abd")))))))
+      (company-idle-begin (current-buffer) (selected-window)
+                          (buffer-chars-modified-tick) (point))
+      (let ((last-command-event ?e))
+        (self-insert-command 1))
+      (company-post-command)
+      (should (eq nil company-candidates-length))
+      (should (eq 4 (point))))))
index e7e054032a3feb81ff177eb4de8820f7c5fddde0..674fc96765d4655fc1a1602a3cf9a2c3930edc58 100644 (file)
@@ -316,7 +316,7 @@ return the cons of buffer and buffer location, or of file and line
 number where the completion candidate was defined.
 
 `require-match': If this value is t, the user is not allowed to enter anything
-not offering as a candidate.  Use with care!  The default value nil gives the
+not offered as a candidate.  Use with care!  The default value nil gives the
 user that choice with `company-require-match'.  Return value 'never overrides
 that option the other way around.
 
@@ -841,14 +841,13 @@ can retrieve meta-data for them."
               (while c2
                 (setcdr c2 (progn (while (equal (pop c2) (car c2)))
                                   c2)))))))
-    (if (and candidates
-             (or (cdr candidates)
-                 (not (eq t (compare-strings (car candidates) nil nil
-                                             prefix nil nil ignore-case)))))
-        candidates
-      ;; Already completed and unique; don't start.
-      ;; FIXME: Not the right place? maybe when setting?
-      (and company-candidates t))))
+    (when candidates
+      (if (or (cdr candidates)
+              (not (eq t (compare-strings (car candidates) nil nil
+                                          prefix nil nil ignore-case))))
+          candidates
+        ;; Already completed and unique; don't start.
+        t))))
 
 (defun company-idle-begin (buf win tick pos)
   (and company-mode