emacs-emojify

fork of https://github.com/iqbalansari/emacs-emojify
Log | Files | Refs | LICENSE

commit 62a32d34bade5279f2c23ce19308bb11f1aa0162
parent 5ba9d59ec44bf018f858c4326faf30b31c8fc320
Author: Iqbal Ansari <iqbalansari02@yahoo.com>
Date:   Sun,  4 Sep 2016 14:19:41 +0530

Fix display of overlapping emojis

Diffstat:
Memojify.el | 15++++++++++++++-
Mtest/emojify-test.el | 13+++++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/emojify.el b/emojify.el @@ -338,8 +338,13 @@ can customize `emojify-inhibit-major-modes' and (json-object-type 'hash-table)) (json-read-file emojify-emoji-json))) + ;; Construct emojify-regexps in descending order of length, this is important + ;; so that larger emojis are searched first and get precedence over smaller + ;; ones (see also `emojify-display-emojis-in-region') (setq emojify-regexps (seq-map #'regexp-opt - (seq-partition (ht-keys emojify-emojis) + (seq-partition (sort (ht-keys emojify-emojis) + (lambda (string1 string2) (> (length string1) + (length string2)))) 1000)))) ;;;###autoload @@ -796,6 +801,14 @@ TODO: Skip emojifying if region is already emojified." (emoji (ht-get emojify-emojis match))) (when (and (memql (intern (ht-get emoji "style")) emojify-emoji-styles) + ;; Skip displaying this emoji if the its bounds are + ;; already part of an existing emoji. Since the emojis + ;; are searched in descending order of length (see + ;; construction of emojify-regexp in `emojify-set-emoji-data'), + ;; this means larger emojis get precedence over smaller + ;; ones + (not (or (get-text-property match-beginning 'emojified) + (get-text-property match-end 'emojified))) ;; Display unconditionally in non-prog mode (or (not (derived-mode-p 'prog-mode 'tuareg--prog-mode 'comint-mode)) ;; In prog mode enable respecting `emojify-program-contexts' diff --git a/test/emojify-test.el b/test/emojify-test.el @@ -325,6 +325,19 @@ (emojify-redisplay-emojis-in-region) (emojify-tests-should-not-be-emojified (+ 14 (point-min))))) +(ert-deftest emojify-tests-overlapping-emojis () + :tags '(core) + (emojify-tests-with-emojified-static-buffer "👲🏽" + (fundamental-mode) + (let ((count 0)) + (emojify-do-for-emojis-in-region (point-min) (point-max) + (incf count)) + ;; Only one emoji should be displayed + (should (= count 1)) + ;; The larger emoji should be preferred + (should (string= (get-text-property (point-min) 'emojify-text) + "👲🏽"))))) + (ert-deftest emojify-tests-emojifying-org-mode-buffers () :tags '(org-mode contextual) (emojify-tests-with-emojified-static-buffer "* Test :books:\n:books:"