[cfe-dev] clang-format: how to avoid aligned indentation on wrapping

Matt Liberty matt.liberty at gmail.com
Sun Feb 1 09:19:01 PST 2015


Thanks for the help.  I had been trying to allow canBreakBefore to allow
the ')' and the '{' to split but it wasn't working very well.  I'll give
the LineJoiner a try instead.

In terms of an option I'm wondering what values UseBraceStyleForOneLiners
would take?  Is it true/false where false implies always breaking and true
is whatever the style does by default?  Perhaps AllowBraceOnWrappedLine?

I don't want to tackle all the various styles Dominique mentioned though
they are interesting.

Matt


On Mon, Jan 26, 2015 at 1:50 AM, Daniel Jasper <djasper at google.com> wrote:

> This doesn't work yet.
>
> To get this addressed, there are basically three somewhat distinct tasks:
> 1) Come up with a way to configure this. I am not yet sure how best to do
> that as the decision is somewhat independent of BreakBeforeBraces. I am
> thinking we might want an additional option UseBraceStyleForOneLiners or
> something. On the other hand, not all combinations make sense (the flag
> would be ineffective for BS_Attach). Maybe somebody else has an idea?
>
> 2) Write tests in unittests/Format/FormatTest.cpp. There are already
> plenty of tests concerning the brace style and we probably want to verify
> that if the configuration is set accordingly, we do the right thing for
> one-liners as well as wrapped statements. And that for
> if/for/while/switch/function/class/...
>
> 3) Implement the behavior. I think the easiest way to achieve this might
> be to use the LineJoiner (lib/Format/UnwrappedLineFormatter.cpp) and allow
> it to merge the "{" back to the previous line if both fit into the
> ColumnLimit.
>
>
> Personal note: I find that style very distracting ;-).
>
> On Sat, Jan 24, 2015 at 7:33 AM, Matt Liberty <matt.liberty at gmail.com>
> wrote:
>
>> Hi
>>
>> I like to keep the { on the same line when wrapping isn't required, eg
>>
>> for (a; b; c) {
>>     d;
>> }
>>
>> but I don't like it on the same line when wrapped:
>>
>> for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
>>      cccccccccccccccccccccccccccccc) {
>>     dddddddddddddddddddddddddddddd;
>> }
>>
>> I find it hard to distinguish the scope quickly as the c's and d's nearly
>> align.  I find:
>>
>> for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
>>      cccccccccccccccccccccccccccccc)
>> {
>>     dddddddddddddddddddddddddddddd;
>> }
>>
>> preferable in this case.  I can't find a why to selectively have the {
>> positioned.  BreakBeforeBraces in Allman style doesn't support the single
>> line case and the others don't support the later case.
>>
>> Is there a way to make work?  If not I'm glad to work on coding a
>> solution but would appreciate some pointers.
>>
>> Thanks,
>> Matt
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150201/a186eb19/attachment.html>


More information about the cfe-dev mailing list