Emacs: Repeat Last Command

Master emacs+lisp, benefit for life. Testimonials. Thank you for support.
,

One command i use few times a day is repeat-complex-command. This command is great to get the elisp code version of a command.

for example, call query-replaceAlt+%】 and type the search text and replacement text. 〔☛ Emacs: Find/Replace Tutorial

Now, to do that again, you can call repeat-complex-command. 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 "xxx" "yyy" nil (if (and transient-mark-mode mark-active) (region-beginning)) (if (and transient-mark-mode mark-active) (region-end)))

(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. 〔☛ Emacs regex tutorial〕 It's also very useful to see elisp version of arguments that are passed by different ways of interactive call.

to really make repeat-complex-command useful, you'll need to give it a easy key. Example:

(global-set-key (kbd "<f8> <f8>") 'repeat-complex-command)

〔☛ Emacs: How to Define Keys

call describe-function to see its inline doc.

(info "(emacs) Repetition")

Like what you read?
Buy Xah Emacs Tutorial
or share some
blog comments powered by Disqus