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

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

[elpa] master 900ae0d 096/173: Add support for company-face


From: Dmitry Gutov
Subject: [elpa] master 900ae0d 096/173: Add support for company-face
Date: Thu, 23 Jun 2016 00:28:41 +0000 (UTC)

branch: master
commit 900ae0d7a2270ea1d2ea00567e80a619333fd4e5
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Add support for company-face
    
    #437.
---
 company.el              |   16 ++++++++++++++++
 test/frontends-tests.el |   25 +++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/company.el b/company.el
index 498920a..18cd2e3 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 7348cbd..b35fe76 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



reply via email to

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