I know that to repeat the last command, there is C-x z and then to keep using z to easily keep the last command in operation, but what can be done for the 2nd or 4th last command? Or is that information lost?
2 Answers
What @Dan said is correct, and it answers your question, which is about any command repeated in any way -- including a command invoked using a key bound to it.
Here is some additional information, which pertains only to so-called complex commands, which means those executed via M-x.
Command
repeat-complex-command, bound toC-x ESC ESC, gives you access to the complete complex-command history. And you can access any command in the history directly by way of a prefix argument -- e.g.,M-2means access the second-from-last command.If you use library
cmds-menu.el(see Recent Commands Menu) then you can access any command in the history directly by choosing it in the menu-bar menu Tools > Recent Commands.
- 77,472
- 10
- 114
- 243
As far as I can tell, in its current implementation, only the most recent command is kept. Everything before that is lost.
I looked at the source code for repeat (the command to which
C-x z is bound), and it uses the variable
last-repeatable-command. Its docstring reads:
last-repeatable-commandis a variable defined inC source code....
Documentation:
Last command that may be repeated. The last command executed that was not bound to an input event. This is the command
repeatwill try to repeat. Taken from a previous value ofreal-this-command.
So last-repeatable-command stores an atom, not a list, and gets
overwritten with the value of real-this-command every time you
invoke a command.
- 32,980
- 7
- 102
- 169
consingthis-commandonto the front of a running list of commands, calling it frompost-command-hook. – Dan Jan 24 '17 at 23:51