abo-abo / hydra

make Emacs bindings that stick around
1.84k stars 112 forks source link

Style 1 does not work with C-M sequence #378

Open mcp292 opened 4 years ago

mcp292 commented 4 years ago

Style 1 does not work with C-M sequence. Seems to be because C-M sequences become C-M-letter and Style 1 expects C-M letter.

abo-abo commented 4 years ago

Works as expected for me. Here's the code I tried:

(defhydra hydra-zoom (global-map "C-M-v")
  "zoom"
  ("g" text-scale-increase "in")
  ("l" text-scale-decrease "out"))
mcp292 commented 4 years ago

Thanks for trying it out. Let me be more clear. This does not work:

(defhydra hydra-zoom (global-map "C-M")
  "zoom"
  ("g" text-scale-increase "in")
  ("l" text-scale-decrease "out"))

Whereas this does:

(defhydra hydra-zoom (global-map "C-c")
  "zoom"
  ("g" text-scale-increase "in")
  ("l" text-scale-decrease "out"))
abo-abo commented 4 years ago

Thing is C-M is not a valid key prefix in Emacs, while C-c is. For example, when you press C-c, Emacs will display C-c- in the Echo Area, as to wait for the complete key sequence. Whereas when you press C-M, nothing happens.

Here's a solution to get the same behavior as you wanted:

(defhydra hydra-zoom (global-map "")
  "zoom"
  ("C-M-g" text-scale-increase "in")
  ("C-M-l" text-scale-decrease "out"))

It requires to put "C-M" in each head, but in the end the behavior is the same.

mcp292 commented 4 years ago

Oh, that makes sense since it's two modifiers. Thanks for the solution! This is what I came up with before changing the bindings:

(defhydra dumb-jump-hydra (global-map "C-M-g" :body-pre (dumb-jump-go))
   "dumb jump"
   ("g" dumb-jump-go "go to declaration")
   ("b" dumb-jump-back "back"))