[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 31063e1 20/29: Fix company-auto-complete and electric-pair
From: |
Dmitry Gutov |
Subject: |
[elpa] master 31063e1 20/29: Fix company-auto-complete and electric-pair-mode compatibility |
Date: |
Tue, 28 Mar 2017 20:50:36 -0400 (EDT) |
branch: master
commit 31063e1992a3b981431d2514d93c8d2a2353912d
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Fix company-auto-complete and electric-pair-mode compatibility
Fixes #650.
---
company.el | 52 ++++++++++++++++++++++++++--------------------------
test/core-tests.el | 20 ++++++++++++++++++++
2 files changed, 46 insertions(+), 26 deletions(-)
diff --git a/company.el b/company.el
index ae7154f..8c4ccac 100644
--- a/company.el
+++ b/company.el
@@ -1457,32 +1457,24 @@ prefix match (same case) will be prioritized."
company-prefix)))
(defun company--continue-failed (new-prefix)
- (let ((input (buffer-substring-no-properties (point) company-point)))
- (cond
- ((company-auto-complete-p input)
- ;; auto-complete
- (save-excursion
- (goto-char company-point)
- (let ((company--auto-completion t))
- (company-complete-selection))
- nil))
- ((and (or (not (company-require-match-p))
- ;; Don't require match if the new prefix
- ;; doesn't continue the old one, and the latter was a match.
- (not (stringp new-prefix))
- (<= (length new-prefix) (length company-prefix)))
- (member company-prefix company-candidates))
- ;; Last input was a success,
- ;; but we're treating it as an abort + input anyway,
- ;; like the `unique' case below.
- (company-cancel 'non-unique))
- ((company-require-match-p)
- ;; Wrong incremental input, but required match.
- (delete-char (- (length input)))
- (ding)
- (message "Matching input is required")
- company-candidates)
- (t (company-cancel)))))
+ (cond
+ ((and (or (not (company-require-match-p))
+ ;; Don't require match if the new prefix
+ ;; doesn't continue the old one, and the latter was a match.
+ (not (stringp new-prefix))
+ (<= (length new-prefix) (length company-prefix)))
+ (member company-prefix company-candidates))
+ ;; Last input was a success,
+ ;; but we're treating it as an abort + input anyway,
+ ;; like the `unique' case below.
+ (company-cancel 'non-unique))
+ ((company-require-match-p)
+ ;; Wrong incremental input, but required match.
+ (delete-char (- company-point (point)))
+ (ding)
+ (message "Matching input is required")
+ company-candidates)
+ (t (company-cancel))))
(defun company--good-prefix-p (prefix)
(and (stringp (company--prefix-str prefix)) ;excludes 'stop
@@ -1517,6 +1509,14 @@ prefix match (same case) will be prioritized."
(setq company-prefix new-prefix)
(company-update-candidates c)
c)
+ ((company-auto-complete-p (buffer-substring-no-properties
+ (point) company-point))
+ ;; auto-complete
+ (save-excursion
+ (goto-char company-point)
+ (let ((company--auto-completion t))
+ (company-complete-selection))
+ nil))
((not (company--incremental-p))
(company-cancel))
(t (company--continue-failed new-prefix)))))
diff --git a/test/core-tests.el b/test/core-tests.el
index 89543b0..6876ed5 100644
--- a/test/core-tests.el
+++ b/test/core-tests.el
@@ -333,6 +333,26 @@
(company-call 'self-insert-command 1))
(should (string= "abcd " (buffer-string))))))
+(ert-deftest company-auto-complete-with-electric-pair ()
+ (with-temp-buffer
+ (insert "foo(ab)")
+ (forward-char -1)
+ (company-mode)
+ (let (company-frontends
+ (company-auto-complete t)
+ (company-auto-complete-chars '(? ?\)))
+ (company-backends
+ (list (lambda (command &optional _)
+ (cl-case command
+ (prefix (buffer-substring 5 (point)))
+ (candidates '("abcd" "abef")))))))
+ (electric-pair-local-mode)
+ (let (this-command)
+ (company-complete))
+ (let ((last-command-event ?\)))
+ (company-call 'self-insert-command 1))
+ (should (string= "foo(abcd)" (buffer-string))))))
+
(ert-deftest company-no-auto-complete-when-idle ()
(with-temp-buffer
(insert "ab")
- [elpa] master updated (4f12749 -> edc5d03), Dmitry Gutov, 2017/03/28
- [elpa] master ec7a860 03/29: Merge pull request #616 from terlar/add-enh-ruby-mode-keyword-alias, Dmitry Gutov, 2017/03/28
- [elpa] master 0499c02 02/29: company-keywords-alist: add enh-ruby-mode -> ruby-mode alias, Dmitry Gutov, 2017/03/28
- [elpa] master 92b0bf7 06/29: Use pipes instead of PTYs to receive output from Clang, Dmitry Gutov, 2017/03/28
- [elpa] master 6f2ae7f 09/29: Merge pull request #621 from juergenhoetzel/use-pipes, Dmitry Gutov, 2017/03/28
- [elpa] master 21357f6 11/29: Update NEWS, Dmitry Gutov, 2017/03/28
- [elpa] master bc2ce4e 18/29: Support Tramp in company-gtags, Dmitry Gutov, 2017/03/28
- [elpa] master b1127da 16/29: Don't show (anonymous) as function annotation, or in argument expansions, Dmitry Gutov, 2017/03/28
- [elpa] master 31063e1 20/29: Fix company-auto-complete and electric-pair-mode compatibility,
Dmitry Gutov <=
- [elpa] master cf98238 04/29: Preview the common part of completion candidates, Dmitry Gutov, 2017/03/28
- [elpa] master 40e2200 07/29: Preview func take the exact common part, Dmitry Gutov, 2017/03/28
- [elpa] master a2ec806 12/29: Use tramp-aware `start-file-process' to start completion process, Dmitry Gutov, 2017/03/28
- [elpa] master a4d0421 05/29: Modified for the original frontends to work, Dmitry Gutov, 2017/03/28
- [elpa] master 1c516df 01/29: Increase the minimum Emacs version dependency, Dmitry Gutov, 2017/03/28
- [elpa] master c494fc6 17/29: Fix a failing test, Dmitry Gutov, 2017/03/28
- [elpa] master ec12e27 27/29: Merge branch 'master' of github.com:company-mode/company-mode, Dmitry Gutov, 2017/03/28
- [elpa] master f149940 28/29: Release 0.9.3, Dmitry Gutov, 2017/03/28
- [elpa] master ce42fcf 23/29: Update copyright years, Dmitry Gutov, 2017/03/28
- [elpa] master 7bd93b8 15/29: Merge pull request #629 from juergenhoetzel/tramp-aware-clang, Dmitry Gutov, 2017/03/28