Emacs: Repeat Last Prompted Command

By Xah Lee. Date: . Last updated: .

One command i use few times a day is repeat-complex-command. This command is great for:

For example, Alt+x query-replaceAlt+%】 and type the search text and replacement text. [see Emacs: Find and Replace Commands]

Now, to do that again, you can Alt+x repeat-complex-commandCtrl+x Alt+:】. Now you don't have to type the search/replacement text again.

But, the extra beauty here is that it shows the elisp code that's actually called. In this case, it's this

(query-replace "aa" "bb" nil (if (use-region-p) (region-beginning)) (if (use-region-p) (region-end)) nil nil)

(it might be slightly different on your emacs setup)

the point here is that, it's a convenient way to get the elisp code of a compex command you just called. This is great if you code emacs lisp. You can use it to translate regex string from interactive form use to the elisp string version, with all proper double backslash escape added. [see Emacs regex tutorial] It's also very useful to see elisp version of arguments that are passed by different ways of interactive call.

See also:

(info "(emacs) Repetition")

Emacs Efficiency Topic

  1. Keyboard Macro
  2. Completion
  3. Abbrev Mode
  4. Use Alias for Fast M-x
  5. Jump to Previous Mark
  6. Repeat Last Prompted Command
  7. Tips on Long Term Emacs Productivity

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp