[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 26/31: Support the keyword :with
From: |
Dmitry Gutov |
Subject: |
[elpa] 26/31: Support the keyword :with |
Date: |
Tue, 18 Mar 2014 05:19:38 +0000 |
dgutov pushed a commit to branch master
in repository elpa.
commit 02d4d06ffcce85485413146890121f8d09381141
Author: Dmitry Gutov <address@hidden>
Date: Sun Mar 16 05:57:56 2014 +0200
Support the keyword :with
Closes #79
---
NEWS.md | 2 ++
company-tests.el | 16 ++++++++++++++++
company-yasnippet.el | 24 +++++++++++++++---------
company.el | 29 ++++++++++++++++++++++++-----
4 files changed, 57 insertions(+), 14 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index 3b4ae78..8ee50e0 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,8 @@
## Next
+* Group of back-ends can now contain keyword `:with`, which makes all back-ends
+ after it to be skipped for prefix calculation.
* New function `company-version`.
* New bundled back-end `company-yasnippet`.
* Completion candidates returned from grouped back-ends are tagged to remember
diff --git a/company-tests.el b/company-tests.el
index 4ac5990..5a26086 100644
--- a/company-tests.el
+++ b/company-tests.el
@@ -87,6 +87,22 @@
(should (equal "13" (company-call-backend 'post-completion (nth 2
candidates))))
(should (equal "42" (company-call-backend 'post-completion (nth 3
candidates)))))))
+(ert-deftest company-multi-backend-handles-keyword-with ()
+ (let ((primo (lambda (command &optional arg)
+ (case command
+ (prefix "a")
+ (candidates '("abb" "abc" "abd")))))
+ (secundo (lambda (command &optional arg)
+ (case command
+ (prefix "a")
+ (candidates '("acc" "acd"))))))
+ (let ((company-backend (list 'ignore 'ignore :with secundo)))
+ (should (null (company-call-backend 'prefix))))
+ (let ((company-backend (list 'ignore primo :with secundo)))
+ (should (equal "a" (company-call-backend 'prefix)))
+ (should (equal '("abb" "abc" "abd" "acc" "acd")
+ (company-call-backend 'candidates "a"))))))
+
(ert-deftest company-begin-backend-failure-doesnt-break-company-backends ()
(with-temp-buffer
(insert "a")
diff --git a/company-yasnippet.el b/company-yasnippet.el
index 27c6812..ae370c7 100644
--- a/company-yasnippet.el
+++ b/company-yasnippet.el
@@ -53,20 +53,26 @@
(defun company-yasnippet (command &optional arg &rest ignore)
"`company-mode' back-end for `yasnippet'.
-This back-end is supposed to be used in a particular way:
+This back-end should be used with care, because as long as there are
+snippets defined for the current major mode, this back-end will always
+shadow back-ends that come after it. Recommended usages:
-* In a buffer-local value of `company-backends'.
-* Grouped with a backend or several that provide actual text completions.
-
-Neither condition is mandatory, but as long as there are snippets defined
-for the current major mode, this back-end will always shadow back-ends that
-come after it. So any other back-ends intended to be used in the current
-buffer should be grouped with it. Example config:
+* In a buffer-local value of `company-backends', grouped with a back-end or
+ several that provide actual text completions.
(add-hook 'js-mode-hook
(lambda ()
(set (make-local-variable 'company-backends)
- '((company-dabbrev-code company-yasnippet))))"
+ '((company-dabbrev-code company-yasnippet)))))
+
+* After keyword `:with', grouped with other back-ends.
+
+ (push '(company-semantic :with company-yasnippet) company-backends)
+
+* Not in `company-backends', just bound to a key.
+
+ (global-set-key (kbd \"C-c y\") 'company-yasnippet)
+"
(interactive (list 'interactive))
(case command
(interactive (company-begin-backend 'company-yasnippet))
diff --git a/company.el b/company.el
index da2e940..a148fa5 100644
--- a/company.el
+++ b/company.el
@@ -306,9 +306,6 @@ If this many lines are not available, prefer to display the
tooltip above."
company-keywords)
company-oddmuse company-files company-dabbrev)
"The list of active back-ends (completion engines).
-Each list elements can itself be a list of back-ends. In that case their
-completions are merged. Otherwise only the first matching back-end returns
-results.
`company-begin-backend' can be used to start a specific back-end,
`company-other-backend' will skip to the next matching back-end in the list.
@@ -383,7 +380,22 @@ modify it, e.g. to expand a snippet.
The back-end should return nil for all commands it does not support or
does not know about. It should also be callable interactively and use
-`company-begin-backend' to start itself in that case."
+`company-begin-backend' to start itself in that case.
+
+Grouped back-ends:
+
+An element of `company-backends' can also itself be a list of back-ends,
+then it's considered to be a \"grouped\" back-end.
+
+When possible, commands taking a candidate as an argument are dispatched to
+the back-end it came from. In other cases, the first non-nil value among
+all the back-ends is returned.
+
+The latter is the case for the `prefix' command. But if the group contains
+the keyword `:with', the back-ends after it are ignored for this command.
+
+The completions from back-ends in a group are merged (but only from those
+that return the same `prefix')."
:type `(repeat
(choice
:tag "Back-end"
@@ -395,6 +407,7 @@ does not know about. It should also be callable
interactively and use
,@(mapcar (lambda (b)
`(const :tag ,(cdr b) ,(car b)))
company-safe-backends)
+ (const :tag "With" :with)
(symbol :tag "User defined"))))))
(put 'company-backends 'safe-local-variable 'company-safe-backends-p)
@@ -587,7 +600,9 @@ The work-around consists of adding a newline.")
;; No initialization for lambdas.
((functionp backend) t)
(t ;; Must be a list.
- (mapc 'company-init-backend backend))))
+ (dolist (b backend)
+ (unless (keywordp b)
+ (company-init-backend b))))))
(defvar company-default-lighter " company")
@@ -776,6 +791,10 @@ means that `company-mode' is always turned on except in
`message-mode' buffers."
when (not (and (symbolp b)
(eq 'failed (get b 'company-init))))
collect b)))
+ (setq backends
+ (if (eq command 'prefix)
+ (butlast backends (length (member :with backends)))
+ (delq :with backends)))
(case command
(candidates
;; Small perf optimization: don't tag the candidates received
- [elpa] 17/31: Add company-yasnippet, (continued)
- [elpa] 17/31: Add company-yasnippet, Dmitry Gutov, 2014/03/18
- [elpa] 22/31: company-sort-by-occurrence: do stable sorting, Dmitry Gutov, 2014/03/18
- [elpa] 20/31: Fix company-yasnippet summary, Dmitry Gutov, 2014/03/18
- [elpa] 23/31: Define company-version, Dmitry Gutov, 2014/03/18
- [elpa] 24/31: company-yasnippet: autoload, to make it easy to use separately, Dmitry Gutov, 2014/03/18
- [elpa] 27/31: company-semantic--current-tags: make buffer-local, Dmitry Gutov, 2014/03/18
- [elpa] 25/31: company-keywords-alist: add missing question mark, Dmitry Gutov, 2014/03/18
- [elpa] 29/31: Remove leftover debug statement, Dmitry Gutov, 2014/03/18
- [elpa] 28/31: company-semantic: don't try to fetch doc for tag without buffer, Dmitry Gutov, 2014/03/18
- [elpa] 08/31: Wrap `company-call-backend' in `condition-case', Dmitry Gutov, 2014/03/18
- [elpa] 26/31: Support the keyword :with,
Dmitry Gutov <=
- [elpa] 30/31: Release 0.7.1, Dmitry Gutov, 2014/03/18
- [elpa] 31/31: Merge commit '7be4321260f0c73ef4c3cadc646f6bb496650253' from company, Dmitry Gutov, 2014/03/18
- [elpa] 21/31: company-init-backend: don't try to initialize lambdas, Dmitry Gutov, 2014/03/18
- [elpa] 03/31: Remove company-bbdb-records, it was unused, Dmitry Gutov, 2014/03/18
- [elpa] 02/31: Declare bbdb functions, instead of requiring it, Dmitry Gutov, 2014/03/18
- [elpa] 06/31: Hopefully fix the Emacs 23 breakage, Dmitry Gutov, 2014/03/18