emacs-elpa-diffs
[Top][All Lists]
Advanced

[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")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]