commit be293295a7aebe22e819aab98e882c81eef53c48
parent 50d2d6da50d9cdd4f0bc93a61f1d89f4a98d7f64
Author: Iqbal Ansari <iqbalansari02@yahoo.com>
Date: Sat, 1 Apr 2017 01:04:27 +0530
Implement support for emojifying company mode tooltips
This is turned off by default for now
Diffstat:
M | emojify.el | | | 36 | ++++++++++++++++++++++++++++++++++++ |
1 file changed, 36 insertions(+), 0 deletions(-)
diff --git a/emojify.el b/emojify.el
@@ -442,6 +442,11 @@ buffer where emojis are going to be displayed selected."
:type 'boolean
:group 'emojify)
+(defcustom emojify-company-tooltips-p nil
+ "Should company mode tooltips be emojified."
+ :type 'boolean
+ :group 'emojify)
+
(defun emojify-in-org-tags-p (match _beg _end)
"Determine whether the point is on `org-mode' tag.
@@ -1944,6 +1949,37 @@ See `tabulated-list-print-entry' to understand the arguments ID and COLS."
+;; Integration with company mode
+
+(defadvice company-pseudo-tooltip-unhide (after emojify-display-emojis-in-company-tooltip (&rest ignored))
+ "Advice to display emojis in company mode tooltips.
+
+This function does two things, first it adds text properties to the completion
+tooltip to make it display the emojis, secondly it makes company always render
+the completion tooltip using `after-string' overlay property rather than
+`display' text property.
+
+The second step is needed because emojify displays the emojis using `display'
+text property, similarly company-mode in some cases uses `display' overlay
+property to render its pop, this results into a `display' property inside
+`display' property, however Emacs ignores recursive text properties. Using
+`after-string' works as well as `display' while allowing the emojis to be
+displayed."
+ (when (and emojify-mode emojify-company-tooltips-p company-pseudo-tooltip-overlay)
+ (let* ((ov company-pseudo-tooltip-overlay)
+ (disp (or (overlay-get ov 'display)
+ (overlay-get ov 'after-string)))
+ (emojified-display (when disp
+ (emojify-string disp))))
+ (when disp
+ (overlay-put ov 'after-string nil)
+ (overlay-put ov 'display (propertize " " 'invisible t))
+ (overlay-put ov 'after-string emojified-display)))))
+
+(ad-activate #'company-pseudo-tooltip-unhide)
+
+
+
;; Integration with some miscellaneous functionality
(defadvice mouse--drag-set-mark-and-point (after emojify-update-emoji-background (&rest ignored))