This post asked a similar question about how to modify formatting when there are too many parameters.
I quite like the rust-fmt styling for this. Is there any way to do this with clang-format?
e.g. 1: with AlignAfterOpenBrackets: AlwaysBreak
return_t foo(
some_t param_1, some_t param_2, some_t param_3,
some_t param_4) {
// function body
}
e.g. 2: desired formatting
return_t foo(
some_t param_1,
some_t param_2,
some_t param_3,
some_t param_4
) {
// function body
}
clang-format AlignAfterOpenBracket just got a new option - BlockIndent (landed on 17/1/22) which does exactly that.
See https://reviews.llvm.org/rG966f24e5a62a:
[clang-format] Add a BlockIndent option to AlignAfterOpenBracket
This style is similar to AlwaysBreak, but places closing brackets on new lines.
For example, if you have a multiline parameter list, clang-format currently only supports breaking per-parameter, but places the closing bracket on the line of the last parameter.
Function( param1, param2, param3);A style supported by other code styling tools (e.g. rustfmt) is to allow the closing brackets to be placed on their own line, aiding the user in being able to quickly infer the bounds of the block of code.
Function( param1, param2, param3 );
This feature is expected to be released in clang-format-14.
In the meantime you could try getting it from the LLVM nightly builds.
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