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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 48/52: Avoid requiring match is certain circumstances


From: Dmitry Gutov
Subject: [elpa] 48/52: Avoid requiring match is certain circumstances
Date: Tue, 01 Jul 2014 11:53:34 +0000

dgutov pushed a commit to branch master
in repository elpa.

commit e5f2d5c2a65e03cd587ee764bee65f0b2de0f8e4
Author: Dmitry Gutov <address@hidden>
Date:   Sat Jun 28 06:00:46 2014 +0300

    Avoid requiring match is certain circumstances
    
    Closes #115
---
 NEWS.md          |    2 ++
 company-tests.el |   26 ++++++++++++++++++++++++++
 company.el       |   20 ++++++++++++--------
 3 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index c0ea782..5364d40 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,8 @@
 
 ## Next
 
+* `company-require-match` is not in effect when the new input doesn't continue
+  the previous prefix, and that prefix was a match.
 * The meaning of `company-begin-commands` value t has slightly changed.
 * New transformer, `company-sort-by-backend-importance`.
 * When grouped back-ends are used, the back-end of the current candidate is
diff --git a/company-tests.el b/company-tests.el
index ea77b61..14b18bc 100644
--- a/company-tests.el
+++ b/company-tests.el
@@ -199,6 +199,7 @@
     (insert "ab")
     (company-mode)
     (let (company-frontends
+          (company-minimum-prefix-length 2)
           (company-require-match 'company-explicit-action-p)
           (company-backends
            (list (lambda (command &optional arg)
@@ -207,11 +208,35 @@
                      (candidates '("abc" "abd")))))))
       (company-idle-begin (current-buffer) (selected-window)
                           (buffer-chars-modified-tick) (point))
+      (should (eq 2 company-candidates-length))
       (let ((last-command-event ?e))
         (company-call 'self-insert-command 1))
       (should (eq nil company-candidates-length))
       (should (eq 4 (point))))))
 
+(ert-deftest company-dont-require-match-if-old-prefix-ended-and-was-a-match ()
+  (with-temp-buffer
+    (insert "ab")
+    (company-mode)
+    (let (company-frontends
+          (company-require-match 'company-explicit-action-p)
+          (company-backends
+           (list (lambda (command &optional arg)
+                   (cl-case command
+                     (prefix (company-grab-word))
+                     (candidates '("abc" "ab" "abd"))
+                     (sorted t))))))
+      (let (this-command)
+        (company-complete))
+      (let ((last-command-event ?e))
+        (company-call 'self-insert-command 1))
+      (should (eq 3 company-candidates-length))
+      (should (eq 3 (point)))
+      (let ((last-command-event ? ))
+        (company-call 'self-insert-command 1))
+      (should (null company-candidates-length))
+      (should (eq 4 (point))))))
+
 (ert-deftest company-should-complete-whitelist ()
   (with-temp-buffer
     (insert "ab")
@@ -281,6 +306,7 @@
     (let (company-frontends
           (company-auto-complete 'company-explicit-action-p)
           (company-auto-complete-chars '(? ))
+          (company-minimum-prefix-length 2)
           (company-backends
            (list (lambda (command &optional arg)
                    (cl-case command
diff --git a/company.el b/company.el
index 23b2317..ccb82ab 100644
--- a/company.el
+++ b/company.el
@@ -1319,7 +1319,7 @@ from the rest of the back-ends in the group, if any, will 
be left at the end."
                                 company-point)
               company-prefix)))
 
-(defun company--continue-failed ()
+(defun company--continue-failed (new-prefix)
   (let ((input (buffer-substring-no-properties (point) company-point)))
     (cond
      ((company-auto-complete-p input)
@@ -1329,17 +1329,21 @@ from the rest of the back-ends in the group, if any, 
will be left at the end."
         (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.
+               (<= (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
+      ;; Wrong incremental input, but required match.
       (delete-char (- (length input)))
       (ding)
       (message "Matching input is required")
       company-candidates)
-     ((equal company-prefix (car 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))
      (t (company-cancel)))))
 
 (defun company--good-prefix-p (prefix)
@@ -1377,7 +1381,7 @@ from the rest of the back-ends in the group, if any, will 
be left at the end."
       c)
      ((not (company--incremental-p))
       (company-cancel))
-     (t (company--continue-failed)))))
+     (t (company--continue-failed new-prefix)))))
 
 (defun company--begin-new ()
   (let (prefix c)



reply via email to

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