From: Dmitry Gutov Date: Sat, 26 Dec 2015 03:10:45 +0000 (+0200) Subject: Add support for company-face X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/900ae0d7a2270ea1d2ea00567e80a619333fd4e5 Add support for company-face #437. --- diff --git a/company.el b/company.el index 498920afb..18cd2e3e9 100644 --- a/company.el +++ b/company.el @@ -2405,6 +2405,7 @@ If SHOW-VERSION is non-nil, show the version in the echo area." '(face company-tooltip-common-selection mouse-face company-tooltip-selection) line))) + (company--apply-company-face line) line)) (defun company--search-chunks () @@ -2417,6 +2418,21 @@ If SHOW-VERSION is non-nil, show the version in the echo area." (push (cons (car md) (cadr md)) res)))) res)) +(defun company--apply-company-face (str) + (let ((start (if (get-text-property 0 'company-face str) + 0 + (next-single-property-change 0 'company-face str))) + end value) + (while start + (setq end (or (next-single-property-change start 'company-face str) + (length str))) + (setq value (get-text-property start 'company-face str)) + (font-lock-prepend-text-property start end 'face value str) + (font-lock-prepend-text-property start end 'mouse-face value str) + (setq start (next-single-property-change end 'company-face str))) + (when end + (remove-text-properties 0 end '(company-face) str)))) + (defun company--clean-string (str) (replace-regexp-in-string "\\([^[:graph:] ]\\)\\|\\(\ufeff\\)\\|[[:multibyte:]]" diff --git a/test/frontends-tests.el b/test/frontends-tests.el index 7348cbde9..b35fe76f6 100644 --- a/test/frontends-tests.el +++ b/test/frontends-tests.el @@ -265,6 +265,31 @@ #(" bar " 0 5 (face company-tooltip mouse-face company-tooltip-mouse)))))) +(ert-deftest company-fill-propertize-uses-company-face () + (let ((company-backend #'ignore) + (company-prefix "") + (str1 "str1") + (str2 "str2")) + (put-text-property 0 3 'company-face 'boo str1) + (put-text-property 1 4 'company-face 'boo str2) + (let ((res (company-fill-propertize str1 nil 10 nil nil nil))) + ;; `equal-including-properties' uses `eq' for properties. + (equal-including-properties + (substring res 3 10) + #(" " 0 6 (face company-tooltip mouse-face company-tooltip-mouse))) + (should (equal (get-text-property 0 'face res) + '(boo company-tooltip))) + (should (equal (get-text-property 2 'mouse-face res) + '(boo company-tooltip-mouse)))) + (let ((res (company-fill-propertize str2 nil 4 nil nil nil))) + (equal-including-properties + (substring res 0 1) + #("s" 0 1 (face company-tooltip mouse-face company-tooltip-mouse))) + (should (equal (get-text-property 1 'face res) + '(boo company-tooltip))) + (should (equal (get-text-property 3 'mouse-face res) + '(boo company-tooltip-mouse)))))) + (ert-deftest company-column-with-composition () :tags '(interactive) (with-temp-buffer