clang-format: features, questions and contributions

Hi everyone,

I’m on a new team with a new style guide and I’m trying to make everyone happy with clang-format. Two issues that have been raised are:

  • We have different formatting guidelines for C vs C++ code.
  • Function declarations should have bin packed parameters but function definitions should have parameters on each line.

I got downloaded and build clang this evening and played with modifying formatting. I’m happy making these changes, if they are possible. Do these sound like features that would be welcome upstream?

I’m thinking about changing BinPackParameters from a boolean to an enum with values something like {Always, DeclarationsOnly, DefinitionsOnly, Never}.

Does that sound possible?
Does clang-format know when it is formatting a declaration vs a definition?

I see a few flags that seem to indicate that it does but it also seemed like it might be a heuristic.

Having different rules for C and C++… I have no idea how I’d distinguish that programmatically.

Can clang-format tell if a file is C or C++? If so, adding a new FormatStyle so I can have different configs in my .clang-format file doesn’t seem too difficult on the surface.

Does this sound like something that would be welcome upstream?

Also, are there any standard scripts to use clang-format with Mercurial? I’ve written my own but it is far from ideal.

Hi Alan,

(snip)

Having different rules for C and C++... I have no idea how I'd distinguish
that programmatically.

Can clang-format tell if a file is C or C++? If so, adding a new FormatStyle
so I can have different configs in my .clang-format file doesn't seem too
difficult on the surface.

It seems easier to filter the list of files, and invoke clang-format
once for C files with one config and again for C++ files with a
different config file.

Csaba