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

Daniel Jasper djasper at google.com
Mon Jan 26 01:50:02 PST 2015


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/20150126/0ce01a02/attachment.html>


More information about the cfe-dev mailing list