<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/118554>118554</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] Add additional format options to break before commas, and align under top bracket
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
d3x0r
</td>
</tr>
</table>
<pre>
https://github.com/d3x0r/llvm-project/tree/d3x0r-add-comma-as-binary-operator is my WIP branch, there are some things I see that could be fixed, or behave better...
- `BreakBeforeComma: true` New option, similar to `BreakBeforeBinaryOperators` or `BreakBeforeBraces`. This adds the binary operator behavior to the tok::comma; it also increases the splitPenalty before ',' and the subsequent token, which drags the comma to the next line. It inherits formatting behaviors of Binary operators by becoming a binary operator, otherwise, it gets ContinuationIndentWidth sort of indenting. I could see where those tests are and make them more specific, rather than making comma a binary operator, but I think it actually fits well.
- `AlignAfterOpenBracket: AlignTop` AlignAfterOpenBracket has a few values it can be `true`, 'Align', 'DontAlign', 'AlwaysBreak', 'BlockIndent'. I would like to maybe add 'AlignTop' as a variation of 'Align'. Align puts arguments that are wrapped under each other, AlignTop would put the wrapped line under the open bracket instead.
Align
```
someLongFunction(argument1,
argument2);
```
AlignTop
```
someLongFunction(argument1,
argument2);
```
AlignTop, __BreakBeforeComma__, SpacesInParensOptions: (InConditionalStatements: true Other: true)
```
someLongFunction( argument1
, argument2 );
```
---
I don't understand why this line gets formatted this way.... (lots of tabs deleted before, since github tabsize is fixed 8)
```
out.data.size
= snprintf( out.data.data, 32, "\x1b[%s;%sR",
y ? GetText( y ) : "0" // col
,
x ? GetText( x ) : "0" ); // row
this.on( & this.common.Output
, SegDuplicate( ( PTEXT ) & out ) );
```
Why does the above get a lone comma get put on the line like that? There's something to do with a comment token , but I don't get it
This is 2 levels of tab indented, and UseTabs is AlignWithSpaces, `ContinuationIndentWidth: 5` , and TabSize:3 ; so the following gets a ContinuationIndentWidth of 5, which is an Indent somehow that gets converted to a tab and 2 spaces.... that continuationindent should be space filled always...
```
\t\tconst simpleContent
\t\t\t = content.replace( "\r\n", "\n" ).replace( "\r", "\n" );
```
a more detailed look at the above 'snprintf' This also had a continuation indent , but all of the arguments under the snprintf were space aligned correctly with space fill....
```
.\tout.data.size
.\t.\t = snprintf( out.data.data, 32, "\x1b[%s;%sR",
.\t y ? GetText( y ) : "0" // col
.\t ,
.\t x ? GetText( x ) : "0" ); // row
```
I did add some unit tests... these are some other examples.
https://github.com/d3x0r/llvm-project/blob/d3x0r-add-comma-as-binary-operator/clang/unittests/Format/FormatTestComma.cpp
All existing format tests pass when none of the above options are used (as they should).
I'm also not sure about the documentation - seems like maybe it's extracted from the header files?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysV1tv47oR_jXMy8CCQsWXPPjBydaFgaJZdF1s3xaUNLLYUKRKUrHdX1_MULKzPsmi7TnBemHzMtdvvhmqEPTBIq7F_EnMv9ypIbbOr-vilPu70tXndRtjH0SxEXIr5PagYzuUWeU6Ibd8SsitMW_drPfun1hFIbfRI067M1XXs8p1nZqpMCu1Vf48cz16FZ0HHaA7w_fdVyi9slUr5DPEFj2C8gjBdQix1fYQYAcB6YeKULnB1FAiNPqENV1xHkps1RtCiTGiz7JM5BuRb2YgFvmTR_X6hI3z-EyGiGID0Q8oFjnAX_EIro_aWRIUdKeN8hDdzcUnNvxltDvQVedvz3hVIW1lAPtWB1B1HcgdSG7DxW02VjvWQ_vRvVKAi02V7HsCHUGZ4EDbyqMKmOSE3uj4Fa0y8QwlKwUhl0I-C7kEZet0aigD_mtAG0kwsmPHVlct1F4dkiRWNKm3eIpgtMUMdhG0bdHrGKBxvlMxanu4GBzANfD0szcBSjKmch2dVLfOcn4op0cdkH7oCAeMAZ6djdoOimK_szXa-F3XsYXgfCQ1mte0PWQAuzHphIEj4yO2LiBEDDEwVsj5Tr3SBnbQUWRCj5VudEVKvSITCD-WjpGlK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