An eloquent sum of a backpacking programmer’s meandering muses

Emacs’ cc-mode’s built-in styles gallery

I, like a lot of programmers, have a preferred style of formatting my source code that makes me happy. So therefore, it was important to me that Emacs understood and indented my code correctly.

Whilst you can manually set each of the individual levels of offsets to apply, it’s usually much simpler to use one of the built-in styles that comes with CC mode. Even if you don’t find one that completely matches your personal style, it is easier to start with one that most closely matches and make slight adjustments, than to start completely from scratch.

What I’d have found useful at the time, would have been an example of what each of the built-in styles looked like. (Sure, it’d not have been too hard to manually set a buffer to each style and re-apply the indentation to use the new style.)

To this end, I present a gallery of examples of the built-in CC mode styles. At the very least, I hope it’ll be a useful reference to people new to Emacs.

To use the style in your current (cc-mode) buffer, use the command C-c . or M-x c-set-style, and then the name of the style. This will not automatically re-format your code. To do so, use the commands C-x hM-C-\ (this puts the region around the entire buffer, and then runs the indent-region command).