How can I get clang-format to break on '<<' and '>>' operators?
I tried setting BreakBeforeBinaryOperators to All, but this does not seem to make any difference here.
I would like my code to be formatted like this:
in >> a
>> b
>> c;
instead of
in >> a >> b >> c;
To achieve this, you need two style settings:
BreakBeforeBinaryOperators: All
ColumnLimit: 0
Or, set the style to the pre-defined WebKit
style, which will set those two style settings for you.
The documentation says:
A column limit of 0 means that there is no column limit. In this case, clang-format will respect the input’s line breaking decisions within statements unless they contradict other rules.
This isn't a great solution, for several reasons:
As the documentation says, clang-format will respect the line breaks that you started with. But it won't add line breaks if they're not already there. So a line in >> a >> b >> c;
will not get broken into separate lines.
The output does not line up the >>
of the first line with the >>
of the subsequent lines. It is simply indented by the usual continued-line amount. For example, if your normal indentation is 4, you will get:
in >> a
>> b
>> c;
This is actually a little strange, because if the operator was <<
, clang-format would line up all three of the operators.
You may, and probably do, want ColumnLimit
set to something else like 80 so that other lines get broken in reasonable places.
But this seems to be the best that can be done with clang-format.
I tested with clang-format 6.0.0, but I believe newer versions will act similarly, and I don't see any new style options which look like they would help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With