Created
February 21, 2016 03:17
-
-
Save tsdeng/b29c590601410185e1ec to your computer and use it in GitHub Desktop.
make other-window command in emacs repeatable, this may save your pinky a bit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'repeat) | |
(defun make-repeatable-command (cmd) | |
"Returns a new command that is a repeatable version of CMD. | |
The new command is named CMD-repeat. CMD should be a quoted | |
command. | |
This allows you to bind the command to a compound keystroke and | |
repeat it with just the final key. For example: | |
(global-set-key (kbd \"C-c a\") (make-repeatable-command 'foo)) | |
will create a new command called foo-repeat. Typing C-c a will | |
just invoke foo. Typing C-c a a a will invoke foo three times, | |
and so on. | |
See related discussion here: | |
http://batsov.com/articles/2012/03/08/emacs-tip-number-4-repeat-last-command/#comment-459843643 | |
https://groups.google.com/forum/?hl=en&fromgroups=#!topic/gnu.emacs.help/RHKP2gjx7I8" | |
(fset (intern (concat (symbol-name cmd) "-repeat")) | |
`(lambda ,(help-function-arglist cmd) ;; arg list | |
,(format "A repeatable version of `%s'." (symbol-name cmd)) ;; doc string | |
,(interactive-form cmd) ;; interactive form | |
;; see also repeat-message-function | |
(setq last-repeatable-command ',cmd) | |
(repeat nil))) | |
(intern (concat (symbol-name cmd) "-repeat"))) | |
(global-set-key (kbd "C-x o") (make-repeatable-command 'other-window)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment