[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 40/52: Define company-sort-by-backend-importance
From: |
Dmitry Gutov |
Subject: |
[elpa] 40/52: Define company-sort-by-backend-importance |
Date: |
Tue, 01 Jul 2014 11:53:30 +0000 |
dgutov pushed a commit to branch master
in repository elpa.
commit 8a7120b84d0a45295c403b50caa430bf58e63649
Author: Dmitry Gutov <address@hidden>
Date: Sun Jun 22 06:57:46 2014 +0300
Define company-sort-by-backend-importance
Closes #110
---
NEWS.md | 1 +
company.el | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index 4c2ffe1..e9738c8 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,7 @@
## Next
+* New transformer, `company-sort-by-backend-importance`.
* When grouped back-ends are used, the back-end of the current candidate is
indicated in the mode-line, enclosed in angle brackets.
* New user option `company-gtags-insert-arguments`, t by default.
diff --git a/company.el b/company.el
index c0e6a98..feea415 100644
--- a/company.el
+++ b/company.el
@@ -452,6 +452,8 @@ Each function gets called with the return value of the
previous one."
:type '(choice
(const :tag "None" nil)
(const :tag "Sort by occurrence" (company-sort-by-occurrence))
+ (const :tag "Sort by back-end importance"
+ (company-sort-by-backend-importance))
(repeat :tag "User defined" (function))))
(defcustom company-completion-started-hook nil
@@ -1221,6 +1223,24 @@ Keywords and function definition names are ignored."
(mapcar #'car (sort occurs (lambda (e1 e2) (<= (cdr e1) (cdr e2)))))
noccurs)))
+(defun company-sort-by-backend-importance (candidates)
+ "Sort CANDIDATES as two priority groups.
+If `company-backend' is a function, do nothing. If it's a list, move
+candidates from back-ends before keyword `:with' to the front. Candidates
+from the rest of the back-ends in the group, if any, will be left at the end."
+ (if (functionp company-backend)
+ candidates
+ (let ((low-priority (cdr (memq :with company-backend))))
+ (if (null low-priority)
+ candidates
+ (sort candidates
+ (lambda (c1 c2)
+ (and
+ (let ((b2 (get-text-property 0 'company-backend c2)))
+ (and b2 (memq b2 low-priority)))
+ (let ((b1 (get-text-property 0 'company-backend c1)))
+ (or (not b1) (not (memq b1 low-priority)))))))))))
+
(defun company-idle-begin (buf win tick pos)
(and (eq buf (current-buffer))
(eq win (selected-window))
- [elpa] 38/52: Indicate current candidate's backend when it's in a group, (continued)
- [elpa] 38/52: Indicate current candidate's backend when it's in a group, Dmitry Gutov, 2014/07/01
- [elpa] 39/52: company-update-group-lighter: privatize, Dmitry Gutov, 2014/07/01
- [elpa] 41/52: Improve comment wording, Dmitry Gutov, 2014/07/01
- [elpa] 37/52: company-pseudo-tooltip-edit: update company-width, Dmitry Gutov, 2014/07/01
- [elpa] 44/52: company-keywords-alist: ass js-mode -> javascript-mode alias, Dmitry Gutov, 2014/07/01
- [elpa] 43/52: company--should-idle-begin: use a more careful check, Dmitry Gutov, 2014/07/01
- [elpa] 42/52: Don't assign to company-point in company-abort and company-finish, Dmitry Gutov, 2014/07/01
- [elpa] 46/52: Never delete the "added newline" twice, Dmitry Gutov, 2014/07/01
- [elpa] 47/52: Don't call post-completion methods and hook in continue-failed case, Dmitry Gutov, 2014/07/01
- [elpa] 45/52: Bring back this-command check when company-idle-delay is t, Dmitry Gutov, 2014/07/01
- [elpa] 40/52: Define company-sort-by-backend-importance,
Dmitry Gutov <=
- [elpa] 49/52: company-backends: add better introduction, Dmitry Gutov, 2014/07/01
- [elpa] 48/52: Avoid requiring match is certain circumstances, Dmitry Gutov, 2014/07/01
- [elpa] 35/52: company-css: Add HTML5 tags and more CSS3 properties, Dmitry Gutov, 2014/07/01
- [elpa] 51/52: Release 0.8.1, Dmitry Gutov, 2014/07/01
- [elpa] 52/52: Merge commit '7c14dedc79bf0c6eaad5bf50b80ea80dd721afdc' from company, Dmitry Gutov, 2014/07/01
- [elpa] 50/52: company-capf.el: Don't ignore things like semantic-capf, Dmitry Gutov, 2014/07/01