1
votes

I'm using clang-format (VSCode built in) to format my CPP code, and I have something like this in my code (before formatting):

input = {18, -11, ..., 11};

There are 100 integers within curly braces.

After formatting with clang-format, it changes into:

input = {
    18,
    -11,
    ...
    11
};

I don't want it to display vertically over 100 lines. But I don't know which style option I have to configure in .clang-format file.

Is there any way to see which style option that is apply to the code (maybe debug/verbose information or something else)? Or I can only see the document of clang format, try every possible one to find the style option that controls it?

Thanks!

The following is the .clang-format file I use.

---
Language: Cpp
BasedOnStyle: Google

AccessModifierOffset: -4
DerivePointerAlignment: false
IndentWidth: 4
SpaceBeforeParens: Never
1
I do not think there is an easy way to figure out which rule broke your formatting. Have you considered putting in a // clang-format off // clang-format on comment pair and moving on?Botje

1 Answers

1
votes
  • There isn't any way to get clang-format to show you which style options applied to which part of your code.
  • One useful link is the configurator, where you can change clang-format style options and watch how your code formatting changes. It also lets you look at how different versions of clang-format would behave.
  • But, it generally does come down to reading the documentation, and trying lots of different style option settings, hoping to find the ones that work for you. After you've done this awhile, you start to understand which style options affect which parts of your code, so it does get easier.
  • For your specific question about the 100 integers in curly braces, the problem you describe is caused by the combination of AlignAfterOpenBracket: DontAlign and BinPackArguments: false. You don't show those settings in your .clang-format file, but they must be there somewhere. Perhaps you are using a different .clang-format file than you think you are? Anyway, the solution is to change one or both of those two settings.