Re: Emojis with quail - but only some

Michael Heerdegen via Users list for the GNU Emacs text editor <[email protected]>
Newsgroups gmane.emacs.help
Message-ID <[email protected]>
Eli Zaretskii <[email protected]> writes:

> > > my goal: I want that hitting : starts the input of an emoji, so that
> > > :+1: would insert ๐Ÿ‘.  Without the need to hit one additional key.

> Did you try to use abbrevs for this?  It sounds like that is what you
> want: have special words that expand into corresponding Emoji.

I guess that would work nicely.  Although I would have to copy
definitions I want and would lose the guidance of the input method.

Meanwhile I even got my approach working.  So far it behaves exactly as
I wanted:

#+begin_src emacs-lisp
(declare-function quail-input-method quail)

(defun my-:-start-emojy-maybe ()
  "Insert a colon (:) and begin typing an emoji starting with \":\".

Typing another \":\" directly after invoking this command prompts for an
emoji to insert (this calls `emoji-search').

The intended usage is to bind this command to [:] in mode maps."
  (interactive)
  (let ((default-input-method           'emoji)
        (default-transient-input-method 'emoji))
    (activate-transient-input-method)
    (let ((events
           ;; `quail-input-method' runs until input is complete
           ;; or terminated and returns a list of character events
           (quail-input-method ?:)))
      (while events
        (if (integerp (car events)) (insert (car events)))
        (setq events (cdr events)))
      (set-transient-map
       (let ((map (make-sparse-keymap)))
         (define-key map [?:]
                     (lambda () (interactive)
                       (delete-char -1)
                       (call-interactively #'emoji-search)))
         map)))))
#+end_src

I intend to use this as binding of [:] in `message-mode-map'.  Hoping
this works reliably...


Michael.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.