I would like clang-format to format like:
switch (x)
{
case long_name: return 1;
case sn: return 2;
}
The AllowShortCaseLabelsOnASingleLine
option gets them on the same line,
but I have not found a way to get the statements aligned.
clang-format supports two ways to provide custom style options: directly specify style configuration in the -style= command line option or use -style=file and put style configuration in the .clang-format or _clang-format file in the project directory.
AlignConsecutiveAssignments ( AlignConsecutiveStyle) clang-format 3.8 Style of aligning consecutive assignments. Consecutive will result in formattings like: Do not align assignments on consecutive lines. Align assignments on consecutive lines. This will result in formattings like:
To configure this in the .clang-format file, use: Reference alignment style (overrides PointerAlignment for references). RAS_Pointer (in configuration: Pointer ) Align reference like PointerAlignment. RAS_Left (in configuration: Left ) Align reference to the left.
The style argument is used to determine the style rules that clang-format will apply. You can use any of the styles described above, or -style=file to tell clang-format that it must use your .clang-format file. By default, clang-format will display formatting discrepancies as shell output. I prefer to have clang-format update the files directly.
As of right now, it's not possible to do what you're asking using ClangFormat.
The official explanation as to why that is:
Each additional style option adds costs to the clang-format project. Some of these costs affect the clang-format development itself, as we need to make sure that any given combination of options work and that new features don’t break any of the existing options in any way. There are also costs for end users as options become less discoverable and people have to think about and make a decision on options they don’t really care about.
The goal of the clang-format project is more on the side of supporting a limited set of styles really well as opposed to supporting every single style used by a codebase somewhere in the wild. [...]
The only way you may be able to do something like that would be to:
Sources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With