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]>
Stefan Monnier via Users list for the GNU Emacs text editor
<[email protected]> writes:

> I suggest you look at `f90-mode-abbrev-table` in `lisp/progmodes/f90.el`
> for an example of an abbrev table which does something similar, tho for
> a different purpose (using the backquote character instead of the colon
> character to start the abbrevs).
>
> Another approach would be to use `completion-at-point-functions`.

Thanks for those hints.

I'm not unhappy with the result of my experiment, though.  This is the
most recent version:

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

(defun my-:-start-emoji-maybe ()
  "Insert a colon (:) and begin typing an emoji starting with \":\".
This temporarily enables the \='emoji\=' input method.
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 ?:)))
      (dolist (e events) (when (integerp e) (insert e)))
      (set-transient-map
       (let ((map (make-sparse-keymap)))
         (define-key map [?:]
                     (lambda () (interactive)
                       (delete-char -1)
                       (call-interactively #'emoji-search)
                       (when-let* ((keys (quail-find-key (char-before)))
                                   ((consp keys)))
                         (message "%S" keys)
                         (sit-for 1))))
         map)))))
#+end_src

While this approach may seem unconventional, is it fundamentally flawed?
A main goal is to avoid duplicating emoji definitions in my
configuration (and, incidentally, I wanted to understand how input
methods function).


Thank you,

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.