clang-format AlignAfterOpenBracket 列表参数

clang-format AlignAfterOpenBracket list params

This post问了一个类似的问题,关于参数过多时如何修改格式。

我非常喜欢这个 rust-fmt 样式。有什么办法可以用 clang-format 做到这一点吗?

例如1: AlignAfterOpenBrackets: AlwaysBreak

return_t foo(
    some_t param_1, some_t param_2, some_t param_3, 
    some_t param_4) {
    // function body
}

例如2: 所需格式

return_t foo(
    some_t param_1, 
    some_t param_2, 
    some_t param_3, 
    some_t param_4
) {
    // function body
}

clang-format AlignAfterOpenBracket 刚刚获得了一个新选项 - BlockIndent(于 22 年 1 月 17 日登陆)正是这样做的。

参见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
);

此功能预计在clang-format-14 发布。
与此同时,您可以尝试从 LLVM nightly builds.

获取它