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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 0a6bfa9 108/173: company-capf: Add :company-prefix-length


From: Dmitry Gutov
Subject: [elpa] master 0a6bfa9 108/173: company-capf: Add :company-prefix-length property function
Date: Thu, 23 Jun 2016 00:28:43 +0000 (UTC)

branch: master
commit 0a6bfa96e02140c76cd80219444ac1b9d42ea197
Author: Fredrik Bergroth <address@hidden>
Commit: Fredrik Bergroth <address@hidden>

    company-capf: Add :company-prefix-length property function
---
 NEWS.md         |    1 +
 company-capf.el |   12 +++++++++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index af75ccb..fab296c 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,7 @@
 
 ## Next
 
+* `company-capf` accepts `:company-prefix-length` property function.
 * New face `company-tooltip-annotation-selection`, used for the annotation in
   the selected tooltip line.
 * `company-clang-objc-templatify` has been renamed to
diff --git a/company-capf.el b/company-capf.el
index 8e28689..6554782 100644
--- a/company-capf.el
+++ b/company-capf.el
@@ -72,9 +72,15 @@
     (`prefix
      (let ((res (company--capf-data)))
        (when res
-         (if (> (nth 2 res) (point))
-             'stop
-           (buffer-substring-no-properties (nth 1 res) (point))))))
+         (let* ((f (plist-get (nthcdr 4 res) :company-prefix-length))
+                (beg (nth 1 res))
+                (end (nth 2 res))
+                (length (and f (funcall f beg (point))))
+                (prefix (buffer-substring-no-properties beg (point))))
+           (cond
+            ((> end (point)) 'stop)
+            (length (cons prefix length))
+            (t prefix))))))
     (`candidates
      (let ((res (company--capf-data)))
        (when res



reply via email to

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