alphapapa / ement.el

A Matrix client for GNU Emacs
GNU General Public License v3.0
476 stars 44 forks source link

New emoji input features in Emacs 29 #199

Closed alphapapa closed 3 months ago

alphapapa commented 10 months ago

@phil-s posted this in the room, which seems to be a very clever solution:

(defun my-ement-room-send-common-reaction (key position)
  "Send a reaction."
  (interactive
   (list (minibuffer-with-setup-hook #'emoji-insert
           (read-string "Reaction: "))
         (point)))
  (ement-room-send-reaction key position))

The (r)ecent sub-menu seems to cater for the "commonly used" case nicely enough (although I've not yet checked whether/how that is persisted between sessions).

Using emoji-search there also works, provided that enable-recursive-minibuffers is enabled.

alphapapa commented 10 months ago

@oantolin suggested this additional hack:

(minibuffer-with-setup-hook
    (lambda ()
      (setq-local after-change-functions
                  (list (lambda (&rest _) (exit-minibuffer)))) 
      (emoji-insert))
  (read-string "Reaction: "))
progfolio commented 10 months ago

Replacing the ement-room-send-message-filter variable with a hook function run in the context of the compose buffer would allow for this and much more. See: #200 for a WIP implementation/examples.

oantolin commented 10 months ago

I have a demo implementation. It's not in a form applicable as a PR, but I could easily do that too, if there's interest. I mention it here so people can try out this UX idea and see if they like it:

alphapapa commented 10 months ago

@oantolin That does look useful, yes. If you have time to prepare a PR or draft PR, feel free.

phil-s commented 7 months ago

I was playing with a little tweak to jump directly to the "Recent" menu simply by having r typed automatically:

(defun my-ement-room-send-common-reaction (key position)
  "Send a reaction."
  (interactive
   (list (minibuffer-with-setup-hook
             (lambda ()
               (activate-input-method 'emoji)
               (push ?r unread-command-events)
               (emoji-insert))
           (read-string "Reaction: "))
         (point)))
  (ement-room-send-reaction key position))

It turned out that in Emacs 29 that "Recent" sub-menu is different to the others, not only in the fact that it builds the options dynamically, but also in being separate from the rest of the transient menu such that you can't 'back out' of that sub-menu with C-g in the way that you can in the other sub-menus. That made it less useful to start in that sub-menu, as it then wouldn't be possible to reach the others.

I didn't understand transient.el enough to figure out how to fix that, but when I tested in my build of Emacs 30 I found that the problem was fixed there.

I then confirmed that emoji.el from my 30.0.50 build also worked in Emacs 29.

So if you want to, you can just copy that version of the library and then my hack works quite nicely.

phil-s commented 3 months ago

I noticed that I'd updated that code since then (to ensure there is an event at point to react to), so here's what I'm currently using. Notes from the previous comment still apply.

(defun my-ement-room-send-common-reaction (key position &optional event)
  "Send a reaction."
  (interactive
   (let ((event (ewoc-data (ewoc-locate ement-ewoc))))
     (unless (ement-event-p event)
       (user-error "No event at point"))
     (list (minibuffer-with-setup-hook
               (lambda ()
                 (activate-input-method 'emoji)
                 (push ?r unread-command-events)
                 (call-interactively #'emoji-insert))
             (read-string "Reaction: "))
           (point)
           event)))
  (ement-room-send-reaction key position event))
alphapapa commented 3 months ago

@phil-s Forgive me, as I haven't grokked these new features yet: Do these "hacks" of yours need to be added to Ement itself to go with Omar's patch? Or are they just for interested users to add to their configs?

phil-s commented 3 months ago

My snippets were independent of #201. I haven't actually tried that PR so I'm not sure how it compares, but I expect it achieves much the same goal and that no one would need my code now that the PR has been merged.

phil-s commented 3 months ago

I've tried it now, and the only "advantage" of my code was that it automatically jumped into the "recent" emoji listing. But (a) I'd needed the emoji.el from Emacs 30 to make that work properly (I couldn't C-g back to the root level otherwise); and (b) in the end it's only the difference between typing s r and s r r; so I don't think that's anything to worry about.