我有一个 C++ 函数调用,我手动和有意格式化为 这个:
DoSomethingForAPurposeThatCausesALongFunctionName(
arg_0,
arg_1,
arg_2);
clang-format 想像这样重新格式化它:
DoSomethingForAPurposeThatCausesALongFunctionName(
arg_0, arg_1, arg_2)
我不想要这个。 AllowAllParametersOfDeclarationOnNextLine
似乎
控制函数声明的这种行为,但是函数调用呢?
有相应的设置吗?
我的 .clang-format
看起来像这样:
BasedOnStyle: Google
BinPackArguments: false
BinPackParameters: false
AllowAllParametersOfDeclarationOnNextLine: false
AlignAfterOpenBracket: AlwaysBreak
最佳答案
我也有兴趣防止在同一行上出现多个参数,但在 fun(
行下方。就我而言,我不介意第一个参数是否仍在同一行作为 fun(
。我只是希望它们要么都在 fun(
行上,要么全部堆叠起来。
我能够通过将 PenaltyBreakBeforeFirstCallParameter
增加到 100 来实现这一点。
据推测,您可能需要不同的值,具体取决于您的其他惩罚设置。
这会产生:
fun(my_long_argument_0,
my_long_argument_1,
my_long_argument_2);
在你的例子中,假设 DoSomethingForAPurposeThatCausesALongFunctionName(arg_0,
对于一行来说太长了,它会产生:
DoSomethingForAPurposeThatCausesALongFunctionName(
arg_0,
arg_1,
arg_2);
关于c++ - clang-format:如何防止下一行的所有函数参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38635106/