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)