在clang格式的长函数签名后使用大括号(和/或圆括号)



我正在尝试为短函数实现以下格式:

void shortFunctionDecl(int x, int y) {
// ...
}

但是如果行太长,我希望它像这样溢出(而不是将参数装箱(

void longerFunctionDecl(
int longName, 
int longName2,
int longName3
) { // I would also be ok if the paren were on the previous line and the brace on this one
// ...
}

目前的代码最终是这样的,读取很烦人

void longerFunctionDecl(
int longName, 
int longName2,
int longName3) { 
// code is at the same indentation level as the args, hard to read.
}

我一直在尝试使用一些BraceWrapping设置,但看起来只有控制语句的多行设置。有可能在clang-format中做我想做的事吗?FWIW,似乎括号中断是不可能的,但我想知道括号中断是否可能?真的不确定。

这是我的.clang-format文件。我已经标记了相关部分,但为了完整起见,我包含了整个部分。

BasedOnStyle: Google
IndentWidth: 4
TabWidth: 4
UseTab: Always
ColumnLimit: 120
AccessModifierOffset: -3
# Relevant portion:
AllowShortFunctionsOnASingleLine: None
BinPackArguments: false
BinPackParameters: false
AlignAfterOpenBracket: AlwaysBreak
AllowAllArgumentsOnNextLine: false

在批准的代码审查中添加了新选项AlignAfterOpenBracket:BlockIndent(2022-01-17(https://reviews.llvm.org/D109557,其为clang格式LLVM 14.0.0-rc1或更高版本。

AlignAfterOpenBracket: BlockIndent: If set, it will always break after an
open bracket, if the parameters don't fit on a single line. Closing brackets
will be placed on a new line.

最新更新