[cmake-developers] Code style auto-formatting

Brad King brad.king at kitware.com
Tue Nov 17 16:35:20 EST 2015


Hi Folks,

For reference, the current CMake indentation style is:

 https://en.wikipedia.org/wiki/Indent_style#Whitesmiths_style

but with 2 space indentation instead of 4 as shown on that page.
The style was popular when CMake started (year 2000) but is not
very widely used anymore.

For Emacs, see attached file (that comes from VTK folks that also
use the style.  For Vim one can use something like:

 set tabstop=2 shiftwidth=2 expandtab
 set cindent cinoptions={1s,l1,g0,c0,t0,(0,W1s

Since the style is not very popular anymore I don't know whether
other editors can be configured for it.  For this reason I've
been thinking about proposing use of clang-format for a while.
We could also consider switching to a more widely-used indentation
style outright and using clang-format to define it formally.

On 11/17/2015 04:29 PM, Daniel Pfeifer wrote:
> On Tue, Nov 17, 2015 at 10:12 PM, Robert Dailey wrote:
>> How did you guys want to approach reformatting inconsistently
>> formatted source files?
> 
> I would say: As a byproduct.
> 
> Adding a .clang-format file to CMake would be greatly appreciated. It
> can be used to ensure that refactorings and new contributions follow
> exactly the predefined style. However, changing existing code simply
> because it does not match the style is something that should be
> refused.

I think we could do a one-shot conversion of existing sources.  This
was done in our CMakeLists.txt and *.cmake files a while ago to update
capitalization style.  We recorded the commit as done by a robot user
instead of a specific developer's name.  It is not that hard to
re-invoke `git blame` to see past any blame poisoning such a commit
might introduce.  For that cost, we gain consistency in the code
and simplicity for patches.

-Brad

-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtk-c-style.el
Type: text/x-emacs-lisp
Size: 1207 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20151117/dd7cc134/attachment.bin>


More information about the cmake-developers mailing list