Monday, January 2, 2012

Binding or Setting Function Keys in GNU Emacs

After learning the basics of emacs, you'll want to start customising your keys.  Function keys are a great place to start since few have default bindings in the stock emacs.

For instance.  If you're a C, C++, or Java developer you'll likely want to compile from within emacs so that you can easily jump to compiler errors.

Last I checked, there is no default key binding for doing this besides
M-x compile
(to set the compile command) and
M-x recompile
(to instantly compile after the compile command has been set.)

I like to compile with F9 (force of habit from an old tool), debug with F10, and set my compile string with F11.

For the above key bindings, add this to the end of your .emacs file:
(global-set-key [f9] 'recompile)
(global-set-key [f10] 'gdb)
(global-set-key [f11] 'compile)