1

I am writing my own Emacs config coming from doom-emacs and Spacemacs. One thing I really miss is the ability to split windows using split-window-below and split-window-right using S-w s s and S-w s v. I am trying to add this to my config and saw that doom-emacs use hydra for this, however, how they do it is like this:

(defhydra +hydra/window-nav (:hint nil)
  ...
  ("s" split-window-below)
  ("v" split-window-right)
  ...)

Can see the source implementation here. I do not understand how it is connected. I tried to just copy their implementation like this:

(defhydra +hydra/window-nav (:hint nil)
  ("s" split-window-below)
  ("v" split-window-right))

But it is not working and did not expect that it would work, since we never bind space for example.. Anyone who could help me?

page290
  • 11
  • 1

2 Answers2

0

Doom and Spacemacs use those keybindings 'directly', no hydra involved. The pop-up window showing the keybindings is provided by the package which-key.

Although you can define all those keybindings directly, I would advise you to start with using either the general.el or the bind-map package.

You can find a minimal example for how to setup a Spacemacs like setup from scratch, using bind-map, here. You can download the README.org file, visit it in Emacs and then do M-x org-babel-tangle to create the init.el file.

B.t.w. in Emacs S-w is not used, and using this might lead to confusion. There is s-w meaning 'super-w' and capital W meaning 'shift-w'. I assume that you mean SPC w here.

dalanicolai
  • 6,108
  • 7
  • 23
  • Just read this now and have a meeting in a few minutes, but doom-emacs use hydra! Watch this link: https://github.com/hlissner/doom-emacs/blob/master/modules/ui/hydra/autoload/windows.el the same I linked above. But when I get home I will try them out and get back to you – page290 Apr 30 '22 at 19:37
  • That code is part of the [hydra module](https://github.com/hlissner/doom-emacs/blob/master/modules/ui/hydra/README.org), you have to add it first to get the hydra (including those keybindings you are pointing at). Normally, it somehow uses the [evil-window-map](https://github.com/emacs-evil/evil/blob/b799fca7adc70536c0c832cb297ce2b8cfe2ae96/evil-maps.el#L140) behind `SPC w`. – dalanicolai Apr 30 '22 at 23:24
  • I find that that [the hydra module is deprecated](https://docs.doomemacs.org/latest/modules/ui/hydra/) b.t.w. So, currently Doom is not using hydra's at all. Thanks to the wizkid who downvoted this answer b.t.w., very useful vote ;) – dalanicolai May 02 '22 at 21:12
  • 1
    @dalanicolai I bumped you back up. I know that you know what you're talking about. – g-gundam Jan 31 '23 at 03:28
  • 1
    @g-gundam Thanks, that's nice! It is indeed not so stimulating, when taking time to investigate things (I am no Doom user) and then (probably correctly) explain how things work, to subsequently get downvoted. But luckily this seems to be an exception. Thanks again for the bump! – dalanicolai Jan 31 '23 at 09:05
0

To understand hydra you should start at the original source page.

For a complete example of window management including your two keys see its wiki entry

You are missing the docstring - ie the menu displayed to the user.

As for binding space - I suspect that is done by Doom's macros which extent the original hydra's ones. In the example quit is done by the head ("q" nil)

I prefer to have the macro for a key binding generate the prompt in most cases so I use pretty hydra

mmmmmm
  • 491
  • 1
  • 4
  • 19