- (loop repeat (prefix-numeric-value repeat-arg) do
- (repeat-self-insert insertion)))
- (call-interactively real-last-command)))
+ ;; If the self-insert had a repeat count, INSERTION
+ ;; includes that many copies of the same character.
+ ;; So use just the first character
+ ;; and repeat it the right number of times.
+ (setq insertion (substring insertion -1))
+ (let ((count (prefix-numeric-value repeat-arg))
+ (i 0))
+ ;; Run pre- and post-command hooks for self-insertion too.
+ (run-hooks 'pre-command-hook)
+ (while (< i count)
+ (repeat-self-insert insertion)
+ (setq i (1+ i)))
+ (run-hooks 'post-command-hook)))
+ (let ((indirect (indirect-function last-repeatable-command)))
+ (if (or (stringp indirect)
+ (vectorp indirect))
+ ;; Bind real-last-command so that executing the macro does
+ ;; not alter it. Do the same for last-repeatable-command.
+ (let ((real-last-command real-last-command)
+ (last-repeatable-command last-repeatable-command))
+ (execute-kbd-macro last-repeatable-command))
+ (run-hooks 'pre-command-hook)
+ (call-interactively last-repeatable-command)
+ (run-hooks 'post-command-hook)))))