From 0a6bfa96e02140c76cd80219444ac1b9d42ea197 Mon Sep 17 00:00:00 2001 From: Fredrik Bergroth Date: Sat, 9 Jan 2016 18:36:32 +0100 Subject: [PATCH] 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 af75ccb6a..fab296c84 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 8e2868925..6554782d1 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 -- 2.39.2