Function: repeat
repeat is an autoloaded, interactive and byte-compiled function
defined in repeat.el.gz.
Signature
(repeat REPEAT-ARG)
Documentation
Repeat most recently executed command.
If REPEAT-ARG is non-nil (interactively, with a prefix argument), supply a prefix argument to that command. Otherwise, give the command the same prefix argument it was given before, if any.
If this command is invoked by a multi-character key sequence, it
can then be repeated by repeating the final character of that
sequence. This behavior can be modified by the global variable
repeat-on-final-keystroke.
repeat ignores commands bound to input events. Hence the term
"most recently executed command" shall be read as "most
recently executed command not bound to an input event".
Probably introduced at or before Emacs version 20.3.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/repeat.el.gz
;;;###autoload
(defun repeat (repeat-arg)
"Repeat most recently executed command.
If REPEAT-ARG is non-nil (interactively, with a prefix argument),
supply a prefix argument to that command. Otherwise, give the
command the same prefix argument it was given before, if any.
If this command is invoked by a multi-character key sequence, it
can then be repeated by repeating the final character of that
sequence. This behavior can be modified by the global variable
`repeat-on-final-keystroke'.
`repeat' ignores commands bound to input events. Hence the term
\"most recently executed command\" shall be read as \"most
recently executed command not bound to an input event\"."
;; The most recently executed command could be anything, so surprises could
;; result if it were re-executed in a context where new dynamically
;; localized variables were shadowing global variables in a `let' clause in
;; here. (Remember that GNU Emacs 19 is dynamically localized.)
;; To avoid that, I tried the `lexical-let' of the Common Lisp extensions,
;; but that entails a very noticeable performance hit, so instead I use the
;; "repeat-" prefix, reserved by this package, for *local* variables that
;; might be visible to re-executed commands, including this function's arg.
(interactive "P")
(when (eq last-repeatable-command 'repeat)
(setq last-repeatable-command repeat-previous-repeated-command))
(cond
((null last-repeatable-command)
(error "There is nothing to repeat"))
((eq last-repeatable-command 'mode-exit)
(error "`last-repeatable-command' is `mode-exit' and can't be repeated"))
((memq last-repeatable-command repeat-too-dangerous)
(error "Command %S too dangerous to repeat automatically"
last-repeatable-command)))
(setq this-command last-repeatable-command
repeat-previous-repeated-command last-repeatable-command
repeat-num-input-keys-at-repeat num-input-keys)
(when (null repeat-arg)
(setq repeat-arg last-prefix-arg))
;; Now determine whether to loop on repeated taps of the final character
;; of the key sequence that invoked repeat. The Emacs global
;; last-command-event contains the final character now, but may not still
;; contain it after the previous command is repeated, so the character
;; needs to be saved.
(let ((repeat-repeat-char
(if (eq repeat-on-final-keystroke t)
last-command-event
;; Allow only specified final keystrokes.
(car (memq last-command-event
(listify-key-sequence
repeat-on-final-keystroke))))))
(if (eq last-repeatable-command (caar command-history))
(let ((repeat-command (car command-history)))
(repeat-message "Repeating %S" repeat-command)
(eval repeat-command))
(if (null repeat-arg)
(repeat-message "Repeating command %S" last-repeatable-command)
(setq current-prefix-arg repeat-arg)
(repeat-message
"Repeating command %S %S" repeat-arg last-repeatable-command))
(when (eq last-repeatable-command 'self-insert-command)
;; We used to use a much more complex code to try and figure out
;; what key was used to run that self-insert-command:
;; (if (<= (- num-input-keys
;; repeat-num-input-keys-at-self-insert)
;; 1)
;; repeat-last-self-insert
;; (let ((range (nth 1 buffer-undo-list)))
;; (condition-case nil
;; (setq repeat-last-self-insert
;; (buffer-substring (car range)
;; (cdr range)))
;; (error (error "%s %s %s" ;Danger, Will Robinson!
;; "repeat can't intuit what you"
;; "inserted before auto-fill"
;; "clobbered it, sorry")))))
(setq last-command-event (char-before)))
(let ((indirect (indirect-function last-repeatable-command)))
(if (or (stringp indirect)
(vectorp indirect))
;; Bind last-repeatable-command so that executing the macro does
;; not alter it.
(let ((last-repeatable-command last-repeatable-command))
(execute-kbd-macro last-repeatable-command))
(call-interactively last-repeatable-command))))
(when repeat-repeat-char
(set-transient-map
(let ((map (make-sparse-keymap)))
(define-key map (vector repeat-repeat-char)
(if (null repeat-message-function) 'repeat
;; If repeat-message-function is let-bound, preserve it for the
;; next "iterations of the loop".
(let ((fun repeat-message-function))
(lambda ()
(interactive)
(let ((repeat-message-function fun))
(setq this-command 'repeat)
;; Beware: messing with `real-this-command' is *bad*, but we
;; need it so `last-repeatable-command' can be recognized
;; later (bug#12232).
(setq real-this-command 'repeat)
(call-interactively 'repeat))))))
map)))))