abo-abo / hydra

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

Getting stuck in amaranth-mode when mixing red and blue #29

Closed luxbock closed 9 years ago

luxbock commented 9 years ago

Starting with emacs -Q:

(let ((default-directory "~/.emacs.d/elpa/"))
    (normal-top-level-add-subdirs-to-load-path))

(require 'hydra)

(defhydra hydra-window (global-map "C-w" :color amaranth)
  "window"
  ("k"   windmove-up "move-up" :color blue)
  ("j"   windmove-down "move-down" :color red)
  ("s"   split-window "split" :color blue))

I load the following and create a few split-windows with C-w s, which works fine. I can move windows up with C-w k just fine as well, but as soon as I use C-w j to try move down a window, the command executes but I get stuck in the amaranth mode with no way to get out. Neither q or C-g help either, so the only way I was able quit was by restarting Emacs.

abo-abo commented 9 years ago

An amaranth body can only have blue and amaranth heads. Red ones don't really make sense. Also note that split-window isn't a command, so it's better to use sexp-style call for it.

The following works fine for me:

(defhydra hydra-test (global-map "C-w" :color amaranth)
  "window"
  ("k" windmove-up "move-up" :color blue)
  ("j" windmove-down "move-down")
  ("s" (split-window) "split" :color blue)
  ("q" nil "quit"))

Although it's a bit strange using amaranth here: you're locked into no-quit mode only after C-w j. This code will lock you in right after C-w.

(global-set-key
 (kbd "C-w")
 (defhydra hydra-window (:color amaranth)
   "window"
   ("h" windmove-left "left")
   ("j" windmove-down "down")
   ("k" windmove-up "up")
   ("l" windmove-right "right")
   ("s" (split-window) "split")
   ("q" nil "cancel")))
luxbock commented 9 years ago

Ah I see!

I think trying to define a body that uses amaranth with red heads should probably throw an error instead of passing for anyone else who might not have read the docs carefully enough. Being stuck in amaranth-mode with no way out can be rather frustrating.

abo-abo commented 9 years ago

Actually, it's OK to do it, it's just redundant. I'm not actually getting an error for this code:

(defhydra hydra-window (global-map "C-w" :color amaranth)
  "window"
  ("k" windmove-up "move-up" :color blue)
  ("j" windmove-down "move-down" :color red)
  ("s" (split-window) "split" :color blue))

I can press C-w jjs and it exits fine.

luxbock commented 9 years ago

It appears to have been an issue with my older Emacs version (24.3). With this version the code above would lock me into amaranth state with no option of getting out. After I upgraded things appear to work fine.

abo-abo commented 9 years ago

OK, I can reproduce it now, thanks. I'll try to fix this soon. The issue didn't come up for me, since the Hydra quitting code has three versions depending on Emacs version.

abo-abo commented 9 years ago

Should be fixed now. If you still have a 24.3 around, try to check.