Cool Emacs :p

4 - macros the easy way

Emacs provides a very easy way of binding complex sequences of keystrokes to a function or single key.

C-x ( - start macro [key presses] - macro contents C-x ) - end macro M-x name-last-kbd-macro - name your macro

The macros is now accessable via

M-x [macro name]

However it will only last as long as your session of emacs is open. In order for it to persist it must be entered into your .emacs file. Fortunately, emacs provides an easy way to do this:

C-x C-f ~/.emacs - open .emacs file M-x insert-key-macro [macro name] - generate appropriate LISP

Additionally, if you'd like to bind this to a key, add the following code to your .emacs, under the above:

(global-set-key "[key]" '[macro name])

For example, amongst other things, I have in my .emacs:

(global-set-key "\C-x\p" 'backward-other-window)
[Contents]