[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 09/16: company-sort-by-occurrence: continue search after predicat
From: |
Dmitry Gutov |
Subject: |
[elpa] 09/16: company-sort-by-occurrence: continue search after predicate fails |
Date: |
Sat, 26 Jul 2014 04:53:22 +0000 |
dgutov pushed a commit to branch master
in repository elpa.
commit b46aa246f4355d6e30195602c35afac7158ddd0f
Author: Dmitry Gutov <address@hidden>
Date: Sun Jul 20 07:47:17 2014 +0300
company-sort-by-occurrence: continue search after predicate fails
---
company.el | 61 ++++++++++++++++++++++++++++++++++-------------------------
1 files changed, 35 insertions(+), 26 deletions(-)
diff --git a/company.el b/company.el
index 662a220..8bc2791 100644
--- a/company.el
+++ b/company.el
@@ -1217,37 +1217,46 @@ Searches for each in the currently visible part of the
current buffer and
prioritizes the matches according to `company-occurrence-weight-function'.
The rest of the list is appended unchanged.
Keywords and function definition names are ignored."
- (let* (occurs
+ (let* ((w-start (window-start))
+ (w-end (window-end))
+ (start-point (point))
+ occurs
(noccurs
- (cl-delete-if
- (lambda (candidate)
- (when (or
- (save-excursion
- (forward-char (- (length company-prefix)))
- (search-backward candidate (window-start) t))
- (save-excursion
- (search-forward candidate (window-end) t)))
- (let ((beg (match-beginning 0))
- (end (match-end 0)))
- (when (save-excursion
- (goto-char end)
- (and (not (memq (get-text-property (point) 'face)
- '(font-lock-function-name-face
- font-lock-keyword-face)))
- (let ((prefix (company--prefix-str
- (company-call-backend 'prefix))))
- (and (stringp prefix)
- (= (length prefix) (- end beg))))))
- (push
- (cons candidate
- (funcall company-occurrence-weight-function beg end))
- occurs)
- t))))
- candidates)))
+ (save-excursion
+ (cl-delete-if
+ (lambda (candidate)
+ (when (catch 'done
+ (goto-char w-start)
+ (while (search-forward candidate w-end t)
+ (when (and (not (eq (point) start-point))
+ (save-match-data
+ (company--occurrence-predicate)))
+ (throw 'done t))))
+ (push
+ (cons candidate
+ (funcall company-occurrence-weight-function
+ (match-beginning 0)
+ (match-end 0)))
+ occurs)
+ t))
+ candidates))))
(nconc
(mapcar #'car (sort occurs (lambda (e1 e2) (<= (cdr e1) (cdr e2)))))
noccurs)))
+(defun company--occurrence-predicate ()
+ (let ((beg (match-beginning 0))
+ (end (match-end 0)))
+ (save-excursion
+ (goto-char end)
+ (and (not (memq (get-text-property (1- (point)) 'face)
+ '(font-lock-function-name-face
+ font-lock-keyword-face)))
+ (let ((prefix (company--prefix-str
+ (company-call-backend 'prefix))))
+ (and (stringp prefix)
+ (= (length prefix) (- end beg))))))))
+
(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
- [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 <=
- [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, 2014/07/26
- [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