(or emacs irrelevant)

Save before compile

Here's a very simplistic function that I was using for a while:

(defun save-and-compile ()
  (compile "make -j4")
  (pop-to-buffer next-error-last-buffer))

It will save the current buffer, run compile and switch to compilation buffer.

Compilation customization

Turns out that there's no need to save, since I get away with this:

(setq compilation-ask-about-save nil)

The documentation says:

Non-nil means M-x compile asks which buffers to save before compiling. Otherwise, it saves all modified buffers without asking.

Select compilation target

A year ago, I wrote a package that looks for a Makefile in the current directory, parses the available targets and allows you to choose one with helm. It's called helm-make. It's almost the same as M-x compile (which also has completion for targets), and it wraps around compile, but I just find it to be more convenient.

This package is as simple as it sounds, the only customization that you can do is to set helm-make-do-save to save all open buffers visiting the Makefile's directory. It also provides, in addition to the plain helm-make command, a helm-make-projectile command, which is almost the same, except the Makefile should come not from the current directory but from projectile-project-root.

Some error navigation to go with your compilation

I've had these bindings for a very long time, just making sure that you're aware of these commands:

(global-set-key [f6] 'next-error)
(global-set-key [C-f6] 'previous-error)

These bindings work for M-x occur and rgrep as well.