]> code.delx.au - gnu-emacs-elpa/commitdiff
company-capf: Add :company-prefix-length property function
authorFredrik Bergroth <fbergroth@gmail.com>
Sat, 9 Jan 2016 17:36:32 +0000 (18:36 +0100)
committerFredrik Bergroth <fbergroth@gmail.com>
Sat, 9 Jan 2016 21:25:45 +0000 (22:25 +0100)
NEWS.md
company-capf.el

diff --git a/NEWS.md b/NEWS.md
index af75ccb6ad659208b2e3247c2ce971378e031ac6..fab296c84a99b6a4067cf3949d1a7b514c64ae00 100644 (file)
--- 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
index 8e2868925a972d38eb7479fdb6c9b9ecf2b545fe..6554782d1de48014e282d5866891b44836578938 100644 (file)
     (`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