Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Replace ascii emoji with unicode in buffer #78

Open
tecosaur opened this issue Oct 24, 2020 · 1 comment
Open

Feature request: Replace ascii emoji with unicode in buffer #78

tecosaur opened this issue Oct 24, 2020 · 1 comment

Comments

@tecosaur
Copy link

Hello!

I find this package great for viewing emoji in emacs, thre's just one related bit of functionality I'd love to see.
For documents like emails I type in Emacs, I'd love it if my ascii emoji could be converted to unicode emoji in the buffer.
This package already does a brilliant job recognising ascii emoji and displaying them as images, so I'm hoping it wouldn't be too much work to add a minor mode which converts ascii emoji to unicode on-type, or a function that I can use as a hook that perfoms such replacements over the buffer (IMO the first option would be preferable).

Thanks for all the work so far 😀

@tecosaur
Copy link
Author

I have tried making such a minor mode, but it's somewhat buggy

(defun emojify--replace-text-with-emoji (orig-fn emoji text buffer start end &optional target)
  "Modify `emojify--propertize-text-for-emoji' to replace ascii/github emoticons with unicode emojis, on the fly."
  (if (or (not emoticon-to-emoji) (= 1 (length text)))
      (funcall orig-fn emoji text buffer start end target)
    (delete-region start end)
    (insert (ht-get emoji "unicode"))))

(define-minor-mode emoticon-to-emoji
  "Write ascii/gh emojis, and have them converted to unicode live."
  :global nil
  :init-value nil
  (if emoticon-to-emoji
      (progn
        (setq-local emojify-emoji-styles '(ascii github unicode))
        (advice-add 'emojify--propertize-text-for-emoji :around #'emojify--replace-text-with-emoji)
        (unless emojify-mode
          (emojify-turn-on-emojify-mode)))
    (setq-local emojify-emoji-styles (default-value 'emojify-emoji-styles))
    (advice-remove 'emojify--propertize-text-for-emoji #'emojify--replace-text-with-emoji)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant