emacs-emojify

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

commit 12c0fb83cfa9a7d26338b4cee0d1cb26757add18
parent 11f17c65564e0a870f634de3f271b0a5ba606e81
Author: Iqbal Ansari <iqbalansari02@yahoo.com>
Date:   Sun, 15 Nov 2015 10:45:09 +0530

Add 'unicode' as possible value of `emojify-emoji-style`

Diffstat:
MREADME.org | 22+++++++++++-----------
Memojify.el | 140++++++++++++++++++++++++++++++++++++++-----------------------------------------
2 files changed, 78 insertions(+), 84 deletions(-)

diff --git a/README.org b/README.org @@ -74,17 +74,17 @@ ** Customizations *** Configuring the types of emojis displayed - Emojify by default displays plain text emojis like ~:)~ as well as github - style emojis ~:smile:~. However it can be instructed to display only one - type of emoji. You can do so by customizing ~emojify-emoji-style~ using the - customize interface. To change the value of the variable from Lisp using the - function ~emojify-set-emoji-style~ (or set it before loading ~emojify~), - call it with one parameter the style of emojis that you want to be - displayed. The possible values are - - - ascii - Display only plain ascii emojis - - github - Display github style emojis - - all - Display all of the above styles + Emojify by default displays plain text emojis (~:)~), unicode emojis (~😄~) + and github style emojis ~:smile:~. However this is customizable. You can do + so by changing the value of ~emojify-emoji-style~ using the customize + interface. To change the value of the variable from Lisp using the function + ~emojify-set-emoji-style~ (or set it before loading ~emojify~), call it with + one parameter the list of styles that you want to be displayed. The possible + styles are + + - ascii - Display only plain ascii emojis + - unicode - Display only unicode emojis + - github - Display only github style emojis *** Configuring how emojis are displayed By default emojis are displayed using images. However you can instruct emojify diff --git a/emojify.el b/emojify.el @@ -200,53 +200,46 @@ can customize `emojify-inhibit-major-modes' and (json-object-type 'hash-table)) (json-read-file emojify-emoji-json))) - (unless (eq emojify-emoji-style 'all) - (let ((style (symbol-name emojify-emoji-style))) - (ht-reject! (lambda (_key value) - (not (string= style (ht-get value "style")))) - emojify-emojis))) + (ht-reject! (lambda (_key value) + (not (memq (intern (ht-get value "style")) emojify-emoji-style))) + emojify-emojis) - (setq emojify-regexps (let ((emojis (ht-keys emojify-emojis))) - (regexp-opt emojis)))) + (setq emojify-regexps (when (ht-keys emojify-emojis) + (let ((emojis (ht-keys emojify-emojis))) + (regexp-opt emojis))))) ;;;###autoload -(defun emojify-set-emoji-style (value) +(defun emojify-set-emoji-style (styles) "Set the type of emojis that should be displayed. VALUE is the value to be used as preferred style, see `emojify-emoji-style'" - (let ((style (if (consp value) - (eval value) - value))) - (unless (memq style '(all github ascii)) - (user-error "[emojify] Do not know how to use `%s' style, please set to one of %s" - value - '(all github ascii))) - (setq-default emojify-emoji-style style) - - ;; Update emoji data - (emojify-set-emoji-data) - - ;; If possible resize emojis, TODO: This should be done in a hook - (when (fboundp 'emojify-redisplay-emojis) - (seq-each (lambda (buffer) - (with-current-buffer buffer - (when emojify-mode - (emojify-redisplay-emojis)))) - (buffer-list))))) + (setq-default emojify-emoji-style styles) + ;; Update emoji data + (emojify-set-emoji-data) + + ;; If possible resize emojis, TODO: This should be done in a hook + (when (fboundp 'emojify-redisplay-emojis) + (seq-each (lambda (buffer) + (with-current-buffer buffer + (when emojify-mode + (emojify-redisplay-emojis)))) + (buffer-list)))) + +;; TODO: Make this a list (defcustom emojify-emoji-style - 'all + '(ascii unicode github) "The type of emojis that should be displayed. These can have one of the following values -`ascii' - Display only ascii emojis for example ';)' -`github' - Display only github style emojis for example ':wink:' -`all' - Display all of the above" - :type '(radio :tag "Emoji Style" - (const :tag "Display only ascii emojis" ascii) - (const :tag "Display only github emojis" github) - (const :tag "Display all emojis" all)) +`ascii' - Display only ascii emojis for example ';)' +`unicode' - Display only unicode emojis for example '😉' +`github' - Display only github style emojis for example ':wink:'" + :type '(set + (const :tag "Display only ascii emojis" ascii) + (const :tag "Display only github emojis" github) + (const :tag "Display only unicode codepoints" unicode)) :set (lambda (_ value) (emojify-set-emoji-style value)) :group 'emojify) @@ -524,43 +517,44 @@ BEG and END are the beginning and end of the region respectively. TODO: Skip emojifying if region is already emojified." (emojify-with-saved-buffer-state (goto-char beg) - (while (and (> end (point)) - (search-forward-regexp emojify-regexps end t)) - (let ((match-beginning (match-beginning 0)) - (match-end (match-end 0)) - (match (match-string-no-properties 0)) - (buffer (current-buffer))) - - ;; Display unconditionally in non-prog mode - (when (and (or (not (derived-mode-p 'prog-mode)) - ;; In prog mode enable respecting `emojify-prog-contexts' - (emojify-valid-prog-context-p match-beginning match-end)) - - ;; The text is at the beginning of the buffer - (emojify-valid-text-context-p match-beginning match-end) - - (not (emojify-inside-org-src-p match-beginning)) - - ;; Inhibit possibly inside a list - ;; 41 is ?) but packages get confused by the extra closing paren :) - ;; TODO Report bugs to such packages - (not (and (eq (char-syntax (char-before match-end)) 41) - (emojify-looking-at-end-of-list-maybe match-end))) - - (not (run-hook-with-args-until-success 'emojify-inhibit-functions match match-beginning match-end))) - - (let ((display-props (emojify--get-text-display-props match))) - (when display-props - (add-text-properties match-beginning - match-end - (append display-props - (list 'emojified t - 'emojify-buffer buffer - 'emojify-text match - 'emojify-start match-beginning - 'emojify-end match-end - 'point-entered #'emojify-point-entered-function - 'help-echo #'emojify-help-function)))))))))) + (when emojify-regexps + (while (and (> end (point)) + (search-forward-regexp emojify-regexps end t)) + (let ((match-beginning (match-beginning 0)) + (match-end (match-end 0)) + (match (match-string-no-properties 0)) + (buffer (current-buffer))) + + ;; Display unconditionally in non-prog mode + (when (and (or (not (derived-mode-p 'prog-mode)) + ;; In prog mode enable respecting `emojify-prog-contexts' + (emojify-valid-prog-context-p match-beginning match-end)) + + ;; The text is at the beginning of the buffer + (emojify-valid-text-context-p match-beginning match-end) + + (not (emojify-inside-org-src-p match-beginning)) + + ;; Inhibit possibly inside a list + ;; 41 is ?) but packages get confused by the extra closing paren :) + ;; TODO Report bugs to such packages + (not (and (eq (char-syntax (char-before match-end)) 41) + (emojify-looking-at-end-of-list-maybe match-end))) + + (not (run-hook-with-args-until-success 'emojify-inhibit-functions match match-beginning match-end))) + + (let ((display-props (emojify--get-text-display-props match))) + (when display-props + (add-text-properties match-beginning + match-end + (append display-props + (list 'emojified t + 'emojify-buffer buffer + 'emojify-text match + 'emojify-start match-beginning + 'emojify-end match-end + 'point-entered #'emojify-point-entered-function + 'help-echo #'emojify-help-function))))))))))) (defun emojify-undisplay-emojis-in-region (beg end) "Undisplay the emojis in region. @@ -659,7 +653,7 @@ runs (only emojify's) point motion hooks." "Turn on `emojify-mode' in current buffer." ;; Calculate emoji data if needed - (unless (and emojify-emojis emojify-regexps) + (unless emojify-emojis (emojify-set-emoji-data)) (when (emojify-buffer-p (current-buffer))