One possibility (based on an original suggestion by Kyle Meyer) is
(global-set-key (kbd "C-c m") 'recompile)
Then you can type C-c m
, which will first offer to save the current buffer if necessary, and then will run the command make -k
in the directory containing the associated file. The -k
switch causes make to try to keep going even if some commands fail. In case you want to modify this, you can type C-u C-c m
and you will get the chance to edit the compilation command in the minibuffer first. The edited command will then be remembered on a per-buffer basis.
Any compilation errors will be shown in a dedicated buffer (called *compilation*
) and you can either click on these with the mouse (to jump to the relevant point in the source file) or use C-x backtick
to cycle through them (sorry, I can't work out how to type a literal backtick inside backticks!). The compilation buffer is not shown if no errors occur but you get a notification in the echo area when compilation is complete.
Of course, you can use any other key of your choice instead of C-c m
- I chose that for the mnemonic m
= "make" and because the C-c letter
keys are reserved for the end-user, so there is little risk of collision.