[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 160ab01 63/66: Split company--process-candidates into -pre
From: |
Dmitry Gutov |
Subject: |
[elpa] master 160ab01 63/66: Split company--process-candidates into -pre and -post |
Date: |
Tue, 13 Jan 2015 02:45:09 +0000 |
branch: master
commit 160ab01fd6ad550bf339a2db59b5d9ab184386c3
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Split company--process-candidates into -pre and -post
* Call the -pre function before saving to cache.
* Copy the candidates list first thing inside the -post function.
* Replace `company-apply-predicate' with `cl-delete-if-not': it's faster.
Fixes #275.
---
company.el | 42 ++++++++++++++++++++++--------------------
1 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/company.el b/company.el
index 8b8f6ca..6d5cc6d 100644
--- a/company.el
+++ b/company.el
@@ -449,9 +449,11 @@ even if the back-end uses the asynchronous calling
convention."
(put 'company-backends 'safe-local-variable 'company-safe-backends-p)
(defcustom company-transformers nil
- "Functions to change the list of candidates received from backends,
-after sorting and removal of duplicates (if appropriate).
-Each function gets called with the return value of the previous one."
+ "Functions to change the list of candidates received from backends.
+
+Each function gets called with the return value of the previous one.
+The first one gets passed the list of candidates, already sorted and
+without duplicates."
:type '(choice
(const :tag "None" nil)
(const :tag "Sort by occurrence" (company-sort-by-occurrence))
@@ -1055,13 +1057,6 @@ can retrieve meta-data for them."
(symbol-name backend))))
(setq company-lighter (format " company-<%s>" name)))))))
-(defun company-apply-predicate (candidates predicate)
- (let (new)
- (dolist (c candidates)
- (when (funcall predicate c)
- (push c new)))
- (nreverse new)))
-
(defun company-update-candidates (candidates)
(setq company-candidates-length (length candidates))
(if (> company-selection 0)
@@ -1107,10 +1102,12 @@ can retrieve meta-data for them."
(cl-return t)))))
(progn
;; No cache match, call the backend.
- (setq candidates (company--fetch-candidates prefix))
- ;; Save in cache (without the predicate applied).
+ (setq candidates (company--preprocess-candidates
+ (company--fetch-candidates prefix)))
+ ;; Save in cache.
(push (cons prefix candidates) company-candidates-cache)))
- (setq candidates (company--process-candidates candidates))
+ ;; Only now apply the predicate and transformers.
+ (setq candidates (company--postprocess-candidates candidates))
(when candidates
(if (or (cdr candidates)
(not (eq t (compare-strings (car candidates) nil nil
@@ -1139,7 +1136,9 @@ can retrieve meta-data for them."
;; or the fetcher called us back right away.
(setq res candidates)
(setq company-backend backend
- company-candidates-cache (list (cons prefix candidates)))
+ company-candidates-cache
+ (list (cons prefix
+ (company--preprocess-candidates candidates))))
(company-idle-begin buf win tick pt)))))
;; FIXME: Relying on the fact that the callers
;; will interpret nil as "do nothing" is shaky.
@@ -1147,15 +1146,18 @@ can retrieve meta-data for them."
(or res
(progn (setq res 'done) nil)))))
-(defun company--process-candidates (candidates)
- (when company-candidates-predicate
- (setq candidates
- (company-apply-predicate candidates
- company-candidates-predicate)))
+(defun company--preprocess-candidates (candidates)
(unless (company-call-backend 'sorted)
- (setq candidates (sort (copy-sequence candidates) 'string<)))
+ (setq candidates (sort candidates 'string<)))
(when (company-call-backend 'duplicates)
(company--strip-duplicates candidates))
+ candidates)
+
+(defun company--postprocess-candidates (candidates)
+ (when (or company-candidates-predicate company-transformers)
+ (setq candidates (copy-sequence candidates)))
+ (when company-candidates-predicate
+ (setq candidates (cl-delete-if-not company-candidates-predicate
candidates)))
(company--transform-candidates candidates))
(defun company--strip-duplicates (candidates)
- [elpa] master a850cdb 51/66: Privatize some search functions (and a var), (continued)
- [elpa] master a850cdb 51/66: Privatize some search functions (and a var), Dmitry Gutov, 2015/01/12
- [elpa] master 7b312dd 52/66: Introduce `company-search-toggle-filtering', Dmitry Gutov, 2015/01/12
- [elpa] master 0d2757c 56/66: company-search-map: Add M-n and M-p bindings, Dmitry Gutov, 2015/01/12
- [elpa] master f5942e9 55/66: company-fill-propertize: Don't highlight match beg till common part, Dmitry Gutov, 2015/01/12
- [elpa] master aa7c1ca 57/66: Simplify NEWS entry, Dmitry Gutov, 2015/01/12
- [elpa] master eb1f0db 58/66: Fixup a test, Dmitry Gutov, 2015/01/12
- [elpa] master 9c99c7c 60/66: company-search-abort: Move predicate reset to the mode function, Dmitry Gutov, 2015/01/12
- [elpa] master 31d352f 53/66: Update NEWS.md, Dmitry Gutov, 2015/01/12
- [elpa] master 559b4f2 49/66: Don't repeat search with empty string, Dmitry Gutov, 2015/01/12
- [elpa] master 388545b 54/66: Add company-complete-common-or-cycle, Dmitry Gutov, 2015/01/12
- [elpa] master 160ab01 63/66: Split company--process-candidates into -pre and -post,
Dmitry Gutov <=
- [elpa] master 8f09f52 61/66: Replace `cl-plusp' usages with `string=', Dmitry Gutov, 2015/01/12
- [elpa] master 5b0f1c8 62/66: company-search-delete-char: Use `ding', Dmitry Gutov, 2015/01/12
- [elpa] master 5ebcae8 64/66: Improve duplicates removal, Dmitry Gutov, 2015/01/12
- [elpa] master 770d0d8 59/66: Work around http://debbugs.gnu.org/19553, Dmitry Gutov, 2015/01/12
- [elpa] master eb0d8d9 65/66: Release 0.8.8, Dmitry Gutov, 2015/01/12
- [elpa] master a95c2ce 42/66: Reorganize tests layout, Dmitry Gutov, 2015/01/12
- [elpa] master 092486e 66/66: Merge commit 'eb0d8d9e687e1364098f9abc6f9281fcbc0d3abd' from company, Dmitry Gutov, 2015/01/12