I am quite bad at counting and remember how many times I have invoked a special command, so I wonder is there any way to count and show in the minibuffer how many time a keyboard macro was invoked? Say that I want to use the macro to navigate the buffer in a specific way, and increment a counter as I move.
- Initialize some counter variable, say
counter, to 0.
(setq counter 0)
- Define the macro
- Give the macro a name, say "some-macro" by
C-x C-k n(
M-x insert-kbd-macro. This will dump the macro out as Lisp code.
(setq counter (1+ counter))to the Lisp code as follows:
(fset 'some-macro (lambda (&optional arg) "Keyboard macro." (interactive "p") (setq counter (1+ counter)) (kmacro-exec-ring-item ...... arg)))
- Evaluate the s-exp.
- Execute your macro by
M-x some-macro. If you find this cumbersome, just define another keyboard to do this...
- To check how many times you've replayed the macro, just evaluate the variable