emacs-elpa-diffs
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]