defrepeater macro to make repeatable versions of commands

Here is an example without using general (never heard of it).

Thank you to Drew Adams and github-alphapapa for the macro. I was just about to implement exactly this sort of repeating command when this macro came up.

CODE

; + + +

(defmacro defrepeater (name command) "Define NAME as an interactive command which calls COMMAND repeatedly. COMMAND is called every time the last key of the sequence bound to NAME is pressed, until another key is pressed." (let* ((docstring (format "Repeatedly call %s'. You may repeatedly press the last key of the sequence bound to this command to repeatedly call%s'." (cadr command) (cadr command)))) `(defun ,name () ,docstring (interactive) (let ((repeat-message-function #'ignore)) (setq last-repeatable-command ,command) (repeat nil)))))

; <f5> <f3> runs the command tb-pulldown, which is a keyboard macro. ; It is bound to <f5> <f3>, C-c C <f3>. ; Macro: C-p NUL C-f C-x r x z C-b C-n C-x r i z C-f

; (define-key tb-special-keymap [f3] 'tb-pulldown)

(defrepeater tb-pulldown-repeat #'tb-pulldown)

(define-key tb-special-keymap [f3] 'tb-pulldown-repeat)

; Typed in the alphabet on one line. ; Now can copy it one character at a time. ; Instead of F5 F3 F5 F3 ... just type F5 F3 F3 F3 ... ; abcdefghijklmnopqrstuvwxyz ; abcdefghijklm

END CODE

/r/emacs Thread