(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))))))
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.
(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