# Is there a way to make the “o” keypress of other-window <C-x><C-o> repeatable?

Question is as stated in the title.

Instead of using various packages for switching windows, it might be simpler to make <C-x><C-o> behave like <C-x><C-+>, such that repeated presses of the o key after the initial <C-x><C-o> will keep switching windows.

• github.com/alphapapa/defrepeater.el looks like a general path to realize such requests as yours. When I tried that out it refused to work occasionally. Finally I stopped using it. But I guess it's worth to be rediscovered. – Marco Wahl Aug 18 '19 at 10:01

I use this in several of my libraries. Use it to make pretty much any command repeatable even when it's on a prefix key.

(defun repeat-command (command)
"Repeat COMMAND."
(require 'repeat)
(let ((repeat-previous-repeated-command  command)
(repeat-message-function           #'ignore)
(last-repeatable-command           'repeat))
(repeat nil)))


Then define a repeatable version of an existing command, such as other-window, just by passing that command to repeat-command. For example:

(defun other-window-repeat ()
"Select another window in cyclic ordering of windows.
This is a repeatable version of other-window'."
(interactive)
(repeat-command 'other-window))

(global-set-key (kbd "C-x 4 o") 'other-window-repeat)


hydra (https://github.com/abo-abo/hydra) are another way to get repeatable commands. This doesn't move the point on the first call, but you can press o as many times as you want to move around.

(defhydra other-window (:color red :body-pre (other-window 1))
"other window"
("o" (other-window 1)))

(global-set-key (kbd "C-x o") #'other-window/body)

• You can add :body-pre (other-window 1) to the hydra arguments to have it move the point on first call. – clemera Aug 18 '19 at 16:20
• Cool, thanks! I only knew of :pre which runs before every head. I updated this solution with your suggestion! – John Kitchin Aug 18 '19 at 19:02

You could write a function similar to text-scale-adjust. E.g.

(defun mw-other-window-repeat (count &optional all-frames)
"Wrapper around other-window' to continue to jump to other with key o."
(interactive "p")
(other-window count all-frames)