[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 5ebcae8 64/66: Improve duplicates removal
From: |
Dmitry Gutov |
Subject: |
[elpa] master 5ebcae8 64/66: Improve duplicates removal |
Date: |
Tue, 13 Jan 2015 02:45:09 +0000 |
branch: master
commit 5ebcae8283b17198ce5f0ee94da7c38c11233259
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Improve duplicates removal
Remove items with equal annotations, even when separated by item(s) with
different annotation(s). Provided the string values match, of course.
---
company.el | 26 +++++++++++++++-----------
test/core-tests.el | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 11 deletions(-)
diff --git a/company.el b/company.el
index 6d5cc6d..4129189 100644
--- a/company.el
+++ b/company.el
@@ -1161,21 +1161,25 @@ can retrieve meta-data for them."
(company--transform-candidates candidates))
(defun company--strip-duplicates (candidates)
- (let ((c2 candidates))
+ (let ((c2 candidates)
+ (annos 'unk))
(while c2
(setcdr c2
- (let ((str (car c2))
- (anno 'unk))
- (pop c2)
+ (let ((str (pop c2)))
(while (let ((str2 (car c2)))
(if (not (equal str str2))
- nil
- (when (eq anno 'unk)
- (setq anno (company-call-backend
- 'annotation str)))
- (equal anno
- (company-call-backend
- 'annotation str2))))
+ (progn
+ (setq annos 'unk)
+ nil)
+ (when (eq annos 'unk)
+ (setq annos (list (company-call-backend
+ 'annotation str))))
+ (let ((anno2 (company-call-backend
+ 'annotation str2)))
+ (if (member anno2 annos)
+ t
+ (push anno2 annos)
+ nil))))
(pop c2))
c2)))))
diff --git a/test/core-tests.el b/test/core-tests.el
index b395c9f..13e547e 100644
--- a/test/core-tests.el
+++ b/test/core-tests.el
@@ -392,6 +392,46 @@
(company-complete-selection)
(should (string= "tea-cup" (buffer-string))))))
+(defvar ct-sorted nil)
+
+(defun ct-equal-including-properties (list1 list2)
+ (or (and (not list1) (not list2))
+ (and (ert-equal-including-properties (car list1) (car list2))
+ (ct-equal-including-properties (cdr list1) (cdr list2)))))
+
+(ert-deftest company-strips-duplicates-within-groups ()
+ (let* ((kvs '(("a" . "b")
+ ("a" . nil)
+ ("a" . "b")
+ ("a" . "c")
+ ("a" . "b")
+ ("b" . "c")
+ ("b" . nil)
+ ("a" . "b")))
+ (fn (lambda (kvs)
+ (mapcar (lambda (kv) (propertize (car kv) 'ann (cdr kv)))
+ kvs)))
+ (company-backend
+ (lambda (command &optional arg)
+ (pcase command
+ (`prefix "")
+ (`sorted ct-sorted)
+ (`duplicates t)
+ (`annotation (get-text-property 0 'ann arg)))))
+ (reference '(("a" . "b")
+ ("a" . nil)
+ ("a" . "c")
+ ("b" . "c")
+ ("b" . nil)
+ ("a" . "b"))))
+ (let ((ct-sorted t))
+ (should (ct-equal-including-properties
+ (company--preprocess-candidates (funcall fn kvs))
+ (funcall fn reference))))
+ (should (ct-equal-including-properties
+ (company--preprocess-candidates (funcall fn kvs))
+ (funcall fn (butlast reference))))))
+
;;; Row and column
(ert-deftest company-column-with-composition ()
- [elpa] master f5942e9 55/66: company-fill-propertize: Don't highlight match beg till common part, (continued)
- [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, 2015/01/12
- [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 <=
- [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