reddit / emacs

Hydras and Mouse Scrolling

Dekula · 2022-02-06 02:15
I've discovered the rather awesome Hydra package, and I like all things about it, except one: I want hydras to function *only* on keys defined. Easy-peasy... EXCEPT, mouse scrolling should work too, and here I've run into the fact that I don't really know how emacs works. I've seen this is a question on the issue tracker without resolution: [https://github.com/abo-abo/hydra/issues/390](https://github.com/abo-abo/hydra/issues/390) I see that as I scroll the mouse, or more accurately touchpad, I get wheel-down/double-wheel-down/triple-wheel-down (or up) and these are all mapped to the same (Mac specific?) event: `mac-mwheel-scroll` but as expected, mapping all the various mouse events I see in lossage to `mac-mwheel-scroll` doesn't work. In fact, mapping them even to normal scroll events only SORT of works. Anyone have any hints? My temporary "solution" is to just use the hydra that allows for other keys, but that is causing some serious OCD. I was thinking of defining a pre command hook that detects whether I am in a hydra and what the command is, but that seems like a hack if there ever was one. Any suggestions?
Dekula · 2022-02-08 01:59
There is a seemingly a very simple way to do this by going into source code and setting a few exceptions (like scrolling) for the amaranth hydra. But besides not wanting to maintain my own fork, I actually realized what I didn't want was adding regular characters into code, more than anything else: i.e., putting an undefined m and getting m back, but maybe I liked the flexibility of being able to do some more advanced bindings, like M-whatever while still in a hydra. I submit this dirty macro as a brute force possibility -- keep in mind I'm using the pretty-hydra package, so this is a macro (dash.el necessary) on top of that rather than a regular hydra: (defmacro my-pretty-hydra-define (name body heads) (let* ((used-keys (->> (--remove (stringp it) heads) (-flatten-n 1) (--map (car it)))) (lower-keys (->> '(q w e r t y i o p a s d h f g h j k l z x c v b n m) (--map (symbol-name it)))) (all-keys (append lower-keys (--map (upcase it) lower-keys))) (unused-keys (-difference all-keys used-keys)) (unused-definitions (-map (lambda (x) `(,x ignore nil)) unused-keys)) (final-heads (append heads `("" ,unused-definitions)))) `(pretty-hydra-define ,name ,body ,final-heads))) This doesn't deal with digits and characters like !@#$% and non-US keyboards but extending that by modifying the `lower-keys` `all-keys` is simple. OCD solved.