[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 13/16: Fix company-occurrence-weight-function
From: |
Dmitry Gutov |
Subject: |
[elpa] 13/16: Fix company-occurrence-weight-function |
Date: |
Sat, 26 Jul 2014 04:53:24 +0000 |
dgutov pushed a commit to branch master
in repository elpa.
commit 3e3815c5d5b1b73da70f5930ebd3130acc565fbc
Author: Dmitry Gutov <address@hidden>
Date: Mon Jul 21 16:10:39 2014 +0300
Fix company-occurrence-weight-function
#152
---
company-tests.el | 34 ++++++++++++++++++++++++++++++++++
company.el | 14 ++++++++------
2 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/company-tests.el b/company-tests.el
index 8bc8572..fc7aec1 100644
--- a/company-tests.el
+++ b/company-tests.el
@@ -714,6 +714,40 @@
(let ((company-backend (list immediate)))
(should (equal '("f") (company-call-backend 'candidates "foo")))))))
+;;; Transformers
+
+(ert-deftest company-occurrence-prefer-closest-above ()
+ (with-temp-buffer
+ (insert "foo0
+foo1
+")
+ (save-excursion
+ (insert "
+foo3
+foo2"))
+ (let ((company-backend 'company-dabbrev)
+ (company-occurrence-weight-function
+ 'company-occurrence-prefer-closest-above))
+ (should (equal '("foo1" "foo0" "foo3" "foo2" "foo4")
+ (company-sort-by-occurrence
+ '("foo0" "foo1" "foo2" "foo3" "foo4")))))))
+
+(ert-deftest company-occurrence-prefer-any-closest ()
+ (with-temp-buffer
+ (insert "foo0
+foo1
+")
+ (save-excursion
+ (insert "
+foo3
+foo2"))
+ (let ((company-backend 'company-dabbrev)
+ (company-occurrence-weight-function
+ 'company-occurrence-prefer-any-closest))
+ (should (equal '("foo1" "foo3" "foo0" "foo2" "foo4")
+ (company-sort-by-occurrence
+ '("foo0" "foo1" "foo2" "foo3" "foo4")))))))
+
;;; Template
(ert-deftest company-template-removed-after-the-last-jump ()
diff --git a/company.el b/company.el
index 8bc2791..7ebc214 100644
--- a/company.el
+++ b/company.el
@@ -1194,22 +1194,23 @@ can retrieve meta-data for them."
(defcustom company-occurrence-weight-function
#'company-occurrence-prefer-closest-above
"Function to weigh matches in `company-sort-by-occurrence'.
-It's called with two arguments: the beginning and the end of the match."
+It's called with three arguments: cursor position, the beginning and the
+end of the match."
:type '(choice
(const :tag "First above point, then below point"
company-occurrence-prefer-closest-above)
(const :tag "Prefer closest in any direction"
company-occurrence-prefer-any-closest)))
-(defun company-occurrence-prefer-closest-above (match-beg match-end)
+(defun company-occurrence-prefer-closest-above (pos match-beg match-end)
"Give priority to the matches above point, then those below point."
- (if (< match-beg (point))
- (- (point) match-end)
+ (if (< match-beg pos)
+ (- pos match-end)
(- match-beg (window-start))))
-(defun company-occurrence-prefer-any-closest (_match-beg match-end)
+(defun company-occurrence-prefer-any-closest (pos _match-beg match-end)
"Give priority to the matches closest to the point."
- (abs (- (point) match-end)))
+ (abs (- pos match-end)))
(defun company-sort-by-occurrence (candidates)
"Sort CANDIDATES according to their occurrences.
@@ -1235,6 +1236,7 @@ Keywords and function definition names are ignored."
(push
(cons candidate
(funcall company-occurrence-weight-function
+ start-point
(match-beginning 0)
(match-end 0)))
occurs)
- [elpa] branch master updated (68ccff3 -> ca001a5), Dmitry Gutov, 2014/07/26
- [elpa] 03/16: company-pseudo-tooltip-frontend: Small rewrite, Dmitry Gutov, 2014/07/26
- [elpa] 06/16: +1 char, -1 line, Dmitry Gutov, 2014/07/26
- [elpa] 05/16: company-pseudo-tooltip-guard: Stabilize when the popup is displayed up, Dmitry Gutov, 2014/07/26
- [elpa] 09/16: company-sort-by-occurrence: continue search after predicate fails, Dmitry Gutov, 2014/07/26
- [elpa] 07/16: Deprecate setting company-idle-delay to t, Dmitry Gutov, 2014/07/26
- [elpa] 08/16: company-sort-by-occurrence: allow customizing the weighing logic, Dmitry Gutov, 2014/07/26
- [elpa] 11/16: company-css-property-value-regexp: prohibit opening curlies, Dmitry Gutov, 2014/07/26
- [elpa] 13/16: Fix company-occurrence-weight-function,
Dmitry Gutov <=
- [elpa] 12/16: company-css-property-values: delete duplicates, Dmitry Gutov, 2014/07/26
- [elpa] 10/16: company-capf: get rid of caching last capf-data, Dmitry Gutov, 2014/07/26
- [elpa] 14/16: Fix tests in batch mode, Dmitry Gutov, 2014/07/26
- [elpa] 01/16: company-frontends-set: never modify VALUE destructively, Dmitry Gutov, 2014/07/26
- [elpa] 15/16: Release 0.8.2, Dmitry Gutov, 2014/07/26
- [elpa] 16/16: Merge commit 'b1d019a4c815ac8bdc240d69eaa74eb4e34640e8' from company-master, Dmitry Gutov, 2014/07/26
- [elpa] 04/16: company-pseudo-tooltip-guard: Invalidate after crossing line continuation, Dmitry Gutov, 2014/07/26
- [elpa] 02/16: Fix popup when prefix is split by line continuation, Dmitry Gutov, 2014/07/26