GNU Coding Standards with clang-format

As an Emacs user, I write most of my C++ code using cc-mode. cc-mode, though, works on regular expressions, which sometimes fail to parse correct C++ code and leave the file inconsistently indented. Even worse, cc-mode doesn’t have support for C++11 features yet. This has served as an annoyance to me for the past few years, but there hasn’t been any alternative until recently.

A new tool, clang-format, is built using the Clang C++ compiler and formats the code by first lexing and parsing it. While this is slower, it leads to better results and even integrates with Emacs. I’ve been unable to use clang-format in most of my projects, though, because both for Humm and Strumm and for personal projects, I tend to use the format from the GNU Coding Standards, adapted to C++, and GNU formatting was not yet supported by clang-format.

I sat down to write a patch for it today, but I found that nine days ago, support was added to the Clang repository. I’m very happy about this news, because it means that the 3.5 version of Clang should ship with it. It’s even in the clang-format-3.5 package in Debian Sid (which, as I write this, corresponds to Clang’s SVN revision r197556), so if you don’t want to try it out from the SVN version and you’re a Debian user, you can just grab it from there!