Search code examples
emacselisp

Is there a (repeat-last-command) in Emacs?


Frequently, I've dug into apropos and docs looking for something like the following only to give up to get back to the task at hand:

(repeat-last-command)

do the last C- or M- command I just executed (to be rebound to a fn key)

or sometimes the related:

(describe-last-function)

what keystroke did I just mistakenly issue, the effect of which I'd like to add to my bag of tricks. describe-key is close, but requires knowing what I typed.

Am I simply asking too much from my trusty sidekick?


Solution

  • with regards to 'describe-last-function':

    There's a variable last-command which is set to a symbol representative of the last thing you did. So this elisp snippet - (describe-function last-command) - ought to bring up the documentation for the thing that immediately happened.

    So you could make a trivial working describe-last-function like so

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

    Put that elisp in .emacs or equivalent, and you'll have a M-x describe-last-function.

    If you've banged on a few keys or done something that modified last-command since the thing you're interested in, the command-history function might be of interest. You can get that by M-x command-history