]> code.delx.au - gnu-emacs-elpa/commitdiff
New user option, company-continue-commands
authorDmitry Gutov <dgutov@yandex.ru>
Sun, 9 Feb 2014 05:26:12 +0000 (07:26 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Sun, 9 Feb 2014 05:26:12 +0000 (07:26 +0200)
Closes #59

NEWS.md
company-tests.el
company.el

diff --git a/NEWS.md b/NEWS.md
index 1382b6efd2311abc2c63ef3ed6da815a170ce21b..8fe5ee69afe52905fab2d646942ac3b79762d471 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,7 @@
 
 ## Next
 
+* New user option `company-continue-commands`.
 * New back-end command, `annotation`, for text displayed inline in the popup
   that's not a part of completion candidate.
 * `company-capf`, `company-clang` and `company-eclim` use `annotation`.
index 8d31ab2fc79fcb8c543e31507f17ba0e1f3a0642..9272f25f244a55ff2f2f3f8bf6bd844ff9d64cd6 100644 (file)
       (should (eq nil company-candidates-length))
       (should (eq 4 (point))))))
 
+(ert-deftest company-should-complete-whitelist ()
+  (with-temp-buffer
+    (insert "ab")
+    (company-mode)
+    (let (company-frontends
+          company-begin-commands
+          (company-backends
+           (list (lambda (command &optional arg)
+                   (case command
+                     (prefix (buffer-substring (point-min) (point)))
+                     (candidates '("abc" "abd")))))))
+      (let ((company-continue-commands nil))
+        (let (this-command)
+          (company-complete))
+        (company-call 'backward-delete-char 1)
+        (should (null company-candidates-length)))
+      (let ((company-continue-commands '(backward-delete-char)))
+        (let (this-command)
+          (company-complete))
+        (company-call 'backward-delete-char 1)
+        (should (eq 2 company-candidates-length))))))
+
+(ert-deftest company-should-complete-blacklist ()
+  (with-temp-buffer
+    (insert "ab")
+    (company-mode)
+    (let (company-frontends
+          company-begin-commands
+          (company-backends
+           (list (lambda (command &optional arg)
+                   (case command
+                     (prefix (buffer-substring (point-min) (point)))
+                     (candidates '("abc" "abd")))))))
+      (let ((company-continue-commands '(not backward-delete-char)))
+        (let (this-command)
+          (company-complete))
+        (company-call 'backward-delete-char 1)
+        (should (null company-candidates-length)))
+      (let ((company-continue-commands '(not backward-delete-char-untabify)))
+        (let (this-command)
+          (company-complete))
+        (company-call 'backward-delete-char 1)
+        (should (eq 2 company-candidates-length))))))
+
 (ert-deftest company-auto-complete-explicit ()
   (with-temp-buffer
     (insert "ab")
 (defun company-call (name &rest args)
   (let* ((maybe (intern (format "company-%s" name)))
          (command (if (fboundp maybe) maybe name)))
+    (let ((this-command command))
+      (run-hooks 'pre-command-hook))
     (apply command args)
     (let ((this-command command))
       (run-hooks 'post-command-hook))))
index 9460e62a644ed0e2e1c6a52cb821e49b3593b169..cc33aa3edb0ea03c386fa7829e117c73b95c6def 100644 (file)
@@ -485,6 +485,16 @@ treated as if it was on this list."
                  (const :tag "Self insert command" '(self-insert-command))
                  (repeat :tag "Commands" function)))
 
+(defcustom company-continue-commands t
+  "A list of commands that are allowed during completion.
+If this is t, or if `company-begin-commands' is t, any command is allowed.
+Otherwise, the value must be a list of symbols.  If it starts with `not',
+the cdr is the list of commands that abort completion.  Otherwise, all
+commands except those in that list, or in `company-begin-commands', or
+commands in the `company-' namespace, abort completion."
+  :type '(choice (const :tag "Any command" t)
+                 (repeat :tag "Commands" function)))
+
 (defcustom company-show-numbers nil
   "If enabled, show quick-access numbers for the first ten candidates."
   :type '(choice (const :tag "off" nil)
@@ -847,6 +857,15 @@ can retrieve meta-data for them."
            (and (symbolp this-command) (get this-command 'company-begin)))
        (not (and transient-mark-mode mark-active))))
 
+(defun company--should-continue ()
+  (or (eq t company-begin-commands)
+      (eq t company-continue-commands)
+      (if (eq 'not (car company-continue-commands))
+          (not (memq this-command (cdr company-continue-commands)))
+        (or (memq this-command company-begin-commands)
+            (memq this-command company-continue-commands)
+            (string-match-p "\\`company-" (symbol-name this-command))))))
+
 (defun company-call-frontends (command)
   (dolist (frontend company-frontends)
     (condition-case err
@@ -1244,7 +1263,9 @@ Keywords and function definition names are ignored."
   (unless (company-keep this-command)
     (condition-case err
         (when company-candidates
-          (company-call-frontends 'pre-command))
+          (company-call-frontends 'pre-command)
+          (unless (company--should-continue)
+            (company-abort)))
       (error (message "Company: An error occurred in pre-command")
              (message "%s" (error-message-string err))
              (company-cancel))))