(ert-deftest company-good-prefix ()
(let ((company-minimum-prefix-length 5)
- company--explicit-action
- (company-selection-changed t)) ;never enough
+ company-abort-manual-when-too-short
+ company--manual-action ;idle begin
+ (company-selection-changed t)) ;has no effect
(should (eq t (company--good-prefix-p "!@#$%")))
(should (eq nil (company--good-prefix-p "abcd")))
(should (eq nil (company--good-prefix-p 'stop)))
(should (eq t (company--good-prefix-p '("foo" . 5))))
- (should (eq nil (company--good-prefix-p '("foo" . 4))))))
+ (should (eq nil (company--good-prefix-p '("foo" . 4))))
+ (should (eq t (company--good-prefix-p '("foo" . t))))))
(ert-deftest company--manual-prefix-set-and-unset ()
(with-temp-buffer
(ert-deftest company-abort-manual-when-too-short ()
(let ((company-minimum-prefix-length 5)
(company-abort-manual-when-too-short t)
- (company-selection-changed t)) ;never enough
- (let ((company--explicit-action nil)) ;idle begin
+ (company-selection-changed t)) ;has not effect
+ (let ((company--manual-action nil)) ;idle begin
(should (eq t (company--good-prefix-p "!@#$%")))
- (should (eq nil (company--good-prefix-p "abcd")))
- (should (eq nil (company--good-prefix-p 'stop)))
(should (eq t (company--good-prefix-p '("foo" . 5))))
- (should (eq nil (company--good-prefix-p '("foo" . 4)))))
- (let ((company--explicit-action t)
+ (should (eq t (company--good-prefix-p '("foo" . t)))))
+ (let ((company--manual-action t)
(company--manual-prefix "abc")) ;manual begin from this prefix
(should (eq t (company--good-prefix-p "!@#$")))
(should (eq nil (company--good-prefix-p "ab")))
(should (eq nil (company--good-prefix-p 'stop)))
(should (eq t (company--good-prefix-p '("foo" . 4))))
(should (eq t (company--good-prefix-p "abcd")))
- (should (eq t (company--good-prefix-p "abcd"))))))
+ (should (eq t (company--good-prefix-p "abc")))
+ (should (eq t (company--good-prefix-p '("bar" . t)))))))
(ert-deftest company-multi-backend-with-lambdas ()
(let ((company-backend
"If enabled, cancel a manually started completion when the prefix gets
shorter than both `company-minimum-prefix-length' and the length of the
prefix it was started from."
- :group 'company
- :type '(choice (const :tag "Off" nil)
- (const :tag "On" t)))
+ :type 'boolean)
(defcustom company-require-match 'company-explicit-action-p
"If enabled, disallow non-matching input.
(defvar company-selection-changed nil)
(make-variable-buffer-local 'company-selection-changed)
-(defvar company--explicit-action nil
- "Non-nil, if explicit completion took place.")
-(make-variable-buffer-local 'company--explicit-action)
+(defvar company--manual-action nil
+ "Non-nil, if manual completion took place.")
+(make-variable-buffer-local 'company--manual-action)
(defvar company--manual-prefix nil)
(make-variable-buffer-local 'company--manual-prefix)
(defun company-explicit-action-p ()
"Return whether explicit completion action was taken by the user."
- (or company--explicit-action
+ (or company--manual-action
company-selection-changed))
(defun company-reformat (candidate)
(defun company-manual-begin ()
(interactive)
(company-assert-enabled)
- (setq company--explicit-action t)
+ (setq company--manual-action t)
(unwind-protect
(let ((company-minimum-prefix-length 0))
(company-auto-begin))
(unless company-candidates
- (setq company--explicit-action nil))))
+ (setq company--manual-action nil))))
(defun company-other-backend (&optional backward)
(interactive (list current-prefix-arg))
(defun company--good-prefix-p (prefix)
(and (stringp (or (car-safe prefix) prefix)) ;excludes 'stop
- (or (and company--manual-prefix
- ;; changed selection not enough for valid prefix
- (not (and company-abort-manual-when-too-short
- ;; must not be less than minimum or initial length
- (< (or (cdr-safe prefix) (length prefix))
- (min company-minimum-prefix-length
- (length company--manual-prefix))))))
- (or (eq (cdr-safe prefix) t)
- (>= (or (cdr-safe prefix) (length prefix))
- company-minimum-prefix-length)))))
+ (or (eq (cdr-safe prefix) t)
+ (let ((len (or (cdr-safe prefix) (length prefix))))
+ (if company--manual-prefix
+ (or (not company-abort-manual-when-too-short)
+ ;; Must not be less than minimum or initial length.
+ (>= len (min company-minimum-prefix-length
+ (length company--manual-prefix))))
+ (>= len company-minimum-prefix-length))))))
(defun company--continue ()
(when (company-call-backend 'no-cache company-prefix)
c (company-calculate-candidates prefix))
;; t means complete/unique. We don't start, so no hooks.
(if (not (consp c))
- (when company--explicit-action
+ (when company--manual-action
(message "No completion found"))
(setq company-prefix prefix)
- (when company--explicit-action
+ (when company--manual-action
(setq company--manual-prefix prefix))
(when (symbolp backend)
(setq company-lighter (concat " " (symbol-name backend))))
company-common nil
company-selection 0
company-selection-changed nil
- company--explicit-action nil
+ company--manual-action nil
company--manual-prefix nil
company-lighter company-default-lighter
company--point-max nil