From: Dmitry Gutov Date: Wed, 15 Jan 2014 02:55:50 +0000 (+0200) Subject: company-capf: Highlight the "common" part X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/4b18b9a65008f74cb53fed88a1e337fecaa3317a company-capf: Highlight the "common" part As in "the part of the candidate up to the last matched character". Now for partial completion, too. --- diff --git a/company-capf.el b/company-capf.el index 2fcfbfb21..8575cd1f5 100644 --- a/company-capf.el +++ b/company-capf.el @@ -77,6 +77,19 @@ Requires Emacs 24.1 or newer." (buffer-substring (nth 1 res) (nth 2 res)) (nth 3 res) (plist-get (nthcdr 4 res) :predicate)))) (cdr (assq 'display-sort-function meta)))))) + (`common-part + ;; Can't just use 0 when base-size (see above) is non-zero. + (let ((start (if (get-text-property 0 'face arg) + 0 + (next-single-property-change 0 'face arg)))) + (when start + ;; completions-common-part comes first, but we can't just look for this + ;; value because it can be in a list. + (or + (let ((value (get-text-property start 'face arg))) + (text-property-not-all start (length arg) + 'face value arg)) + (length arg))))) (`duplicates nil) ;Don't bother. (`no-cache t) ;FIXME: Improve! (`meta diff --git a/company.el b/company.el index 1a324c723..5d1355e0a 100644 --- a/company.el +++ b/company.el @@ -1677,34 +1677,40 @@ Example: \(company-begin-with '\(\"foo\" \"foobar\" \"foobarbaz\"\)\)" (pop copy)) (apply 'concat pieces))) +(defun company--highlight-common (line properties) + ;; XXX: Subject to change. + (let ((common (or (company-call-backend 'common-part line) + (length company-common)))) + (add-text-properties 0 common properties line))) + (defun company-fill-propertize (line width selected) - (setq line (company-safe-substring line 0 width)) - (add-text-properties 0 width '(face company-tooltip - mouse-face company-tooltip-mouse) - line) - (add-text-properties 0 (length company-common) - '(face company-tooltip-common - mouse-face company-tooltip-mouse) - line) - (when selected - (if (and company-search-string - (string-match (regexp-quote company-search-string) line - (length company-prefix))) - (progn - (add-text-properties (match-beginning 0) (match-end 0) - '(face company-tooltip-selection) - line) - (when (< (match-beginning 0) (length company-common)) - (add-text-properties (match-beginning 0) (length company-common) - '(face company-tooltip-common-selection) - line))) - (add-text-properties 0 width '(face company-tooltip-selection - mouse-face company-tooltip-selection) - line) - (add-text-properties 0 (length company-common) - '(face company-tooltip-common-selection - mouse-face company-tooltip-selection) - line))) + (let ((common (or (company-call-backend 'common-part line) + (length company-common)))) + (setq line (company-safe-substring line 0 width)) + (add-text-properties 0 width '(face company-tooltip + mouse-face company-tooltip-mouse) + line) + (add-text-properties 0 common '(face company-tooltip-common + mouse-face company-tooltip-mouse) + line) + (when selected + (if (and company-search-string + (string-match (regexp-quote company-search-string) line + (length company-prefix))) + (progn + (add-text-properties (match-beginning 0) (match-end 0) + '(face company-tooltip-selection) + line) + (when (< (match-beginning 0) common) + (add-text-properties (match-beginning 0) common + '(face company-tooltip-common-selection) + line))) + (add-text-properties 0 width '(face company-tooltip-selection + mouse-face company-tooltip-selection) + line) + (add-text-properties 0 common '(face company-tooltip-common-selection + mouse-face company-tooltip-selection) + line)))) line) ;;; replace