I tend to build very often when working; in this post, I describe how I went from a build every few minutes to automatic builds on every file change.

The underlying idea is this: if something is hard to do, you’ll avoid doing it. Point in case, if you have to type M-x compile RET in order to build, you usually won’t. Since I think you shouldn’t be limited by your tools, I wanted something that would build automatically in the background.

My solution is, a bash script that uses inotify to watch a set of files for changes, and calls make whenever a change occurs. Basically, it calls inotifywait, followed by make in a loop:


Over the past few months, this short script has made development much more pleasant for me. So much so, that I now use it for everything from compiling LaTeX, to building Haskell. In fact, if I’m not browsing the web, my screen almost always looks like this now:

Emacs Layout
Emacs Layout

Running it is also straightforward; here are some of my recent invocations. Each time, I call on the source files of each project:

% Main.hs templates/* r/* \
  posts/* Makefile
% Makefile *.tex
% $(find src/ -name '*.java')
% $(find . -name '*.xml' \
  -o -name '*.scala')

The last time I showed to somebody, they remarked that it’s like flymake, but worse. Although it’s far less featureful, it does have one advantage over flymake and other similar systems: will work out of the box with any project that has a Makefile.

I’d love to hear suggestions for improving, or about other people’s workflows in the comments.