abo-abo / hydra

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

A few questions / suggestions #24

Closed joostkremers closed 9 years ago

joostkremers commented 9 years ago

This is cool! I can now finally scroll through a buffer with space and backspace:

(defhydra hydra-scroll (global-map "C-S-SPC")
  "scroll"
  ("SPC" scroll-up-command "down")
  ("<backspace>" scroll-down-command "up"))

A few questions:

The last two questions are inspired by the menu that org-export-dispatch pops up. I'd be nice to have something similar to that but more general. But perhaps that's not the direction you want to take hydra...

abo-abo commented 9 years ago

This is cool! I can now finally scroll through a buffer with space and backspace:

(defhydra hydra-scroll (global-map "C-S-SPC") "scroll" ("SPC" scroll-up-command "down") ("" scroll-down-command "up"))

Neat! I'm still using C-v and M-v, but C-v is such a good binding, it would be cool to free it up.

Would it be possible to have the comment appear when I press
C-S-SPC? Right now, it seems to be displayed only after I hit
space or backspace at least once.

It's possible with this code:

(global-set-key 
 (kbd "C-S-SPC")
 (defhydra hydra-scroll ()
   "scroll"
   ("SPC" scroll-up-command "down")
   ("<backspace>" scroll-down-command "up")))

Note though, that with this approach you'll be sacrificing C-S-SPC as a prefix, so e.g. you can't bind C-S-SPC f any more. This is because the above code basically calls (global-set-key (kbd "C-S-SPC") 'hydra-scroll/body).

Is it possible to add comments for the prefix arguments
(digit-argument, negative-argument and universal-argument)?

You could bind them yourself, I guess. They're not present to save space. I haven't yet figured out a hint display strategy for when there are really a lot of bindings. My largest one currently has 14, and it still looks sort-of OK, but any more than that would look too much.

It'd be great if it were possible to have the comment appear in
a popup window rather than in the echo area. (Not necessarily by
default, but by using some keyword argument).

This is an option, although I don't know if popping up windows is a rigorously solved problem, in case the user has a complex layout. So I was staying away from this for the moment. If you can recommend a core library that can do this, I'd like to try.

Is it possible to create chained hydras, where one head calls
forth another hydra?

Yes. It's possible, although I haven't yet explored it:

(global-set-key
 (kbd "C-z")
 (defhydra hydra-vi (:color amaranth)
   "vi"
   ("l" forward-char)
   ("h" backward-char)
   ("j" next-line)
   ("k" previous-line)
   ("t" hydra-vi-toggle/body "modes" :color blue)
   ("q" nil "quit")))

(defhydra hydra-vi-toggle (:color blue
                           :post hydra-vi/body)
  "vi-toggle"
  ("a" abbrev-mode "abbrev")
  ("d" toggle-debug-on-error "debug")
  ("f" auto-fill-mode "fill")
  ("t" toggle-truncate-lines "truncate")
  ("w" whitespace-mode "whitespace")
  ("q" nil "cancel"))

The first defhydra leaves its body available via hydra-vi/body, and the second via hydra-vi-toggle/body. These are plain commands that can be called and combined.

joostkremers commented 9 years ago

Thanks for your extensive answer. I haven't had time to check out your suggestions yet, will do in the next few days.

As for popping up windows, I'm really only aware of the popwin library:

https://github.com/m2ym/popwin-el

Can't really say how good it is with complex window configs, though. I rarely have more than two windows in a frame...

srid commented 9 years ago

Off-topic, but I really like your hydra-scroll. It comes in handy when viewing images in Emacs. The default SPC and S+SPC scrolls a pageful, but with hydra-scroll I can 'pan' the image quickly and smoothly with just j and k.