See also: LoopFindPackage
Here’s an attempt at detecting repetition.
The program below notices when you have typed the same key sequence (between a minimum and maximum length) at least a certain number of times. It optionally displays the detected sequence in the mini-buffer, stores it in a variable (repdet-most-recent-sequence) and writes it to a buffer.
Pressing ‘F11’ then sets the last detected pattern as a keyboard macro in last-kbd-macro and ‘F12’ runs it.
This code doesn’t work around the C-u problem (each command is called repeatedly, whether that “counts” or not is not decided, yet).
Load the file, do the same thing three times and a buffer “Detected Repetitions will be created, containing the repeated events.
“M-x customize-group repdet RET” can be used to customise some aspects of the behaviour.
The last 6 lines get the code running, and set up key bindings to turn it on and off.