- (when company-candidates
- (when (funcall company-backend 'no-cache company-prefix)
- ;; Don't complete existing candidates, fetch new ones.
- (setq company-candidates-cache nil))
- (let ((new-prefix (funcall company-backend 'prefix)))
- (unless (and (= (- (point) (length new-prefix))
- (- company-point (length company-prefix)))
- (or (equal company-prefix new-prefix)
- (let ((c (company-calculate-candidates new-prefix)))
- ;; t means complete/unique.
- (if (eq c t)
- (progn (company-cancel new-prefix) t)
- (when (consp c)
- (setq company-prefix new-prefix)
- (company-update-candidates c)
- t)))))
- (if (company-auto-complete-p company-point (point))
- (save-excursion
- (goto-char company-point)
- (company-complete-selection)
+ (when (funcall company-backend 'no-cache company-prefix)
+ ;; Don't complete existing candidates, fetch new ones.
+ (setq company-candidates-cache nil))
+ (let ((new-prefix (funcall company-backend 'prefix)))
+ (unless (and (= (- (point) (length new-prefix))
+ (- company-point (length company-prefix)))
+ (or (equal company-prefix new-prefix)
+ (let ((c (company-calculate-candidates new-prefix)))
+ ;; t means complete/unique.
+ (if (eq c t)
+ (progn (company-cancel new-prefix) t)
+ (when (consp c)
+ (setq company-prefix new-prefix)
+ (company-update-candidates c)
+ t)))))
+ (if (company-auto-complete-p company-point (point))
+ (save-excursion
+ (goto-char company-point)
+ (company-complete-selection)
+ (setq company-candidates nil))
+ (if (not (and (company-incremental-p company-prefix new-prefix)
+ (company-require-match-p)))
+ (progn
+ (when (equal company-prefix (car company-candidates))
+ ;; cancel, but last input was actually success
+ (company-cancel company-prefix))