The option allows users to specify how many columns to use to indent
designated initializers that start on a new line.
This addresses the corresponding github issue, albeit in a slightly different way to what was proposed there.
Differential D146101
[clang-format] Add DesignatedInitializerIndentWidth option. jp4a50 on Tue, Mar 14, 3:29 PM. Authored by
Details The option allows users to specify how many columns to use to indent This addresses the corresponding github issue, albeit in a slightly different way to what was proposed there.
Diff Detail
Event Timeline
Comment Actions Please see https://clang.llvm.org/docs/ClangFormatStyleOptions.html#adding-additional-style-options. Is there a way to fix the issue without adding a new option?
Comment Actions Change DesignatedInitializerIndentWidth to a signed integer which defaults to ContinuationIndentWidth when set to -1.
Comment Actions @owenpan We could simply change the indentation level of designated initializers for everyone to match IndentWidth instead of ContinuationIndentWidth but I suspect that other users might be unhappy if we made that breaking change? I guess we could also consider making this behaviour only kick in when a specific set of *other* options are specified (e.g. AlwaysBreak) so that it applies to our clang-format style and not *all* others but that just feels like a hack. I understand the added complexity and maintenance burden of a new option but we do meet the 3 criteria listed in your link.
I think it's also worth noting that the google style guide gives an example of designated initializers indented at 2 spaces (whereas their "continuation indent" for wrapped function parameters is 4). Comment Actions The style guide doesn't mention indenting designated initializers with 2 spaces?
It's likely an error that the designated initializer example there shows 2-space indents as clang-format uses the 4-space continuation indent width: clang-format -style=Google Point p = { .x = 1.0, .y = 2.0, // z will be 0.0 }; Point p = { .x = 1.0, .y = 2.0, // z will be 0.0 }; Comment Actions
That is a fair point. I will get it updated because the author and maintainer of that style guide is the one requesting this change since, in practice, codebases following this style guide indent designated initializers with 2 spaces.
This is possible, but isn't it also possible that they would prefer designated initializers to be indented at 2 spaces but don't have the option with clang-format currently? The only general information supplied in the google style guide about indentation is as follows:
If we are taking a strict definition of parameters, the above suggests to me that designated initializers would fall under the default indentation of 2 spaces. As mentioned on my other diff, I'm away until next Monday now so won't be able to get back to further comments til then. Comment Actions What I'd really like to see, is... in the event that ContinuationIndentWidth is set and I do NOTset DesignatedInitializerIndentWidth , then DesignatedInitializerIndentWidth would inherit from that (not the default as you have here), if I set ContinuationIndentWidthto 3 DesignatedInitializerIndentWidth should be 3 Otherwise if I set DesignatedInitializerIndentWidth explicitly then it can be what is set, i.e. (for base LLVM style) ContinuationIndentWidth is not set = (default) 4 DesignatedInitializerIndentWidth = not set (implicitly 4) ContinuationIndentWidth is set = 3 DesignatedInitializerIndentWidth = not set (implicitly 3) ContinuationIndentWidth is not set = (default) 4 DesignatedInitializerIndentWidth = is set to 2 (explicitly 2) ContinuationIndentWidth is set = 3 DesignatedInitializerIndentWidth = is set to 4 (explicitly 4)
|