Does Emacs have (repeat-last command)?

Often times, I dug into apropos and docs to find something like the following to give up on going back to the task:

(repeat last command)

run the last C or M command I just ran (to get back to the fn key)

or sometimes related:

(describe-last-functions)

what keystroke I am just mistakenly giving out, an effect I would like to add to my bag of tricks. description-key is close but requires knowledge of what I've typed.

Am I just asking too much from my trusted friend?

+119


source to share


8 answers


in regards to describe-last-function :

There is a variable here last-command

that is set by a symbol representing the last thing you did. So this elisp snippet - (describe-function last-command)

- should provide documentation of what happened immediately.

This way you can do trivial work describe-last-function

like



(defun describe-last-function() 
  (interactive) 
  (describe-function last-command))

      

Place this elisp in, .emacs

or its equivalent, and you have a descriptive -Mx function .

If you hit multiple keys or do something that changed the last command as you are interested, the function command-history

might be of interest. You can get this with Mx command-history

+54


source


The repeat function is provided by the repeat.el

Emacs Lisp package , which is included with the standard Emacs distributions. From the documentation repeat.el

:

This package defines a command that repeats the previous command, whatever it is, including its arguments, whatever they are. This command is connected to the Cx z key. To repeat the previous command once, type Cx z. Repeat this a second time just after, type only z. By typing z over and over, you can repeat the command over and over.



For more information on a repeat command, type C-h F repeat RETfrom Emacs.

+161


source


Repeat last command

C-x z

Once you clicked, just click only z after that and it will repeat (without clicking again C-x).

+140


source


You can repeat commands with C-x zand press zto keep repeating.

Slightly shocking no one mentioned repeat-complex-command

, accessible from key bindings C-x ESC ESC.

+67


source


It also M-x view-lossage

shows you the last hundreds (?) Of keys pressed. This way you will be able to see where the team is. This is what I used until I just found out about M-x command-history

, which I think I will now use with C-h w

.

+21


source


I'm not sure, but maybe you are looking for this one?

The C-x z( repeat

) command provides another way to repeat the Emacs command over and over. This command repeats the previous Emacs command, whatever it is. Repeating a command uses the same arguments used before; he doesn't read new arguments every time.

The Emacs Manual 8.11 Command Repeating

+17


source


Maybe that would help too ... From emacs Help verbatim:

C-x M-ESC runs the command repeat-complex-command
  which is an interactive compiled Lisp function in `simple.el'.
It is bound to <again>, <redo>, C-x M-:, C-x M-ESC.
(repeat-complex-command ARG)

Edit and re-evaluate last complex command, or ARGth from last.
A complex command is one which used the minibuffer.
The command is placed in the minibuffer as a Lisp form for editing.
The result is executed, repeating the command as changed.
If the command has been changed or is not the most recent previous command
it is added to the front of the command history.
You can use the minibuffer history commands M-n and M-p
to get different commands to edit and resubmit.

      

+9


source


Personally, I found Sebastian's idea useful. Here is a working version

(global-set-key "\C-r" #'(lambda () (interactive)
                                 (eval (car command-history))))

      

+3


source







All Articles