[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 03/14: New user option, company-continue-commands
From: |
Dmitry Gutov |
Subject: |
[elpa] 03/14: New user option, company-continue-commands |
Date: |
Tue, 18 Feb 2014 05:51:01 +0000 |
dgutov pushed a commit to branch master
in repository elpa.
commit f8d57add8cf97f1135b5b644f9a06e3b4ffc1e6a
Author: Dmitry Gutov <address@hidden>
Date: Sun Feb 9 07:26:12 2014 +0200
New user option, company-continue-commands
Closes #59
---
NEWS.md | 1 +
company-tests.el | 46 ++++++++++++++++++++++++++++++++++++++++++++++
company.el | 23 ++++++++++++++++++++++-
3 files changed, 69 insertions(+), 1 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index 1382b6e..8fe5ee6 100644
--- 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`.
diff --git a/company-tests.el b/company-tests.el
index 8d31ab2..9272f25 100644
--- a/company-tests.el
+++ b/company-tests.el
@@ -117,6 +117,50 @@
(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")
@@ -383,6 +427,8 @@
(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))))
diff --git a/company.el b/company.el
index 9460e62..cc33aa3 100644
--- a/company.el
+++ b/company.el
@@ -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))))
- [elpa] branch master updated (2e6b4f6 -> cae1efc), Dmitry Gutov, 2014/02/18
- [elpa] 04/14: Fix scrolling up from the last item, Dmitry Gutov, 2014/02/18
- [elpa] 06/14: Introduce company-dabbrev-downcase, Dmitry Gutov, 2014/02/18
- [elpa] 01/14: Set company-added-newline to t if the buffer was modified, Dmitry Gutov, 2014/02/18
- [elpa] 02/14: Don't `company-cancel' twice, Dmitry Gutov, 2014/02/18
- [elpa] 05/14: Fix out-of-bounds error on truncated anno fontification, Dmitry Gutov, 2014/02/18
- [elpa] 07/14: company-capf: fix when company-point is nil, Dmitry Gutov, 2014/02/18
- [elpa] 03/14: New user option, company-continue-commands,
Dmitry Gutov <=
- [elpa] 08/14: company--capf-data: Check that the cdr is cons, not data itself, Dmitry Gutov, 2014/02/18
- [elpa] 09/14: company-capf common-part: look up font-lock-face, Dmitry Gutov, 2014/02/18
- [elpa] 10/14: company-capf: cache the capf data, Dmitry Gutov, 2014/02/18
- [elpa] 14/14: Merge commit '119822078ee3024c2d27017d45ef4578fa36040f' from company, Dmitry Gutov, 2014/02/18
- [elpa] 12/14: company-continue-commands: change the default value, Dmitry Gutov, 2014/02/18
- [elpa] 13/14: Bump the version, Dmitry Gutov, 2014/02/18
- [elpa] 11/14: common-part: rename to `match' and document, Dmitry Gutov, 2014/02/18