Recording a macro in Emacs is a well known tasks, but today I struggled with applying the macro for the current region only. Thanks to this answer on SO, I ended with the following recipe:
- Select region
F3
M-x narrow-to-region
- … operations on region,
M-<
to jump to beginning of region,M->
to the end M-x widen
F4
When you want to save your macro for later usage, run
M-x name-last-kbd-macro Enter <mymacro> Enter
- Open
.emacs
M-x insert-kbd-macro Enter <mymacro> Enter
- Add line
(global-set-key [f9] '<mymacro>)
to bindF9
to your macro