emacshydra

emacs elisp (other-window 0)


I try to write a hydra function to switch windows. Basically I want that C-x o takes me to the other window, and then "o" will cycle through all the windows. So I put in .emacs

(global-set-key
   (kbd "C-x o")
   (defhydra hydra-other-window (:pre (other-window 1))
     "hydra other window"
     ("o" (other-window 1) "Next window")))

It does not work. C-x o does take me to the other window, but press "o" does nothing. However if I change 1 in the last line to 0, it works as expected. It is quite surprising because according the documentation, (other-window 0) will just select in the current window. Is there a good explanation for this? Any help will be appreciated.


Solution

  • You can use a simpler code:

    (defhydra hydra-other-window (global-map "C-x")
      "hydra other window"
      ("o" (other-window 1) "Next window"))