All Projects → alphapapa → defrepeater.el

alphapapa / defrepeater.el

Licence: GPL-3.0 license
Easily define repeatable Emacs commands

Programming Languages

emacs lisp
2029 projects

defrepeater.el

https://melpa.org/packages/defrepeater-badge.svg

This package lets you easily define “repeating commands,” which are commands that can be repeated by pressing the last key of the sequence bound to it.

For example, let’s say that you use winner-mode, and you have C-c C-w p bound to winner-undo. Obviously, pressing that whole sequence repeatedly is tiresome when you want to go several steps back. But using this macro, you can press C-c C-w p once, and then keep pressing p to repeat winner-undo, until you press a different key (you could press C-g if you needed to stop the repetition so you could press p normally).

Usage

First, define repeating commands:

;; Automatically defines `winner-redo-repeat' command:
(defrepeater #'winner-redo)

;; Optionally specify the name of the repeater, like using `defalias':
(defrepeater 'winner-undo-repeat #'winner-undo)

Then bind keys to the new commands (example using general):

(general-def
  [remap winner-redo] #'winner-redo-repeat
  [remap winner-undo] #'winner-undo-repeat)

For example, M-SPC w p was bound to winner-undo, so now M-SPC w p p p can be pressed to call winner-undo 3 times.

defrepeater can also be used directly in a key-binding expression:

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

Installation

MELPA

If you installed from MELPA, you’re done.

Manual

Put defrepeater.el in your load-path, and (require 'defrepeater) in your init file.

Changelog

1.0

Initial release.

Credits

This was inspired by this answer by Drew Adams. Thanks also to Fox Keister for his feedback.

Development

Bug reports, feature requests, suggestions — oh my!

License

GPLv3

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].