![](/img/trans.png)
[英]clang-format: break on function arguments instead of function qualifiers (noexcept)
[英]clang-format: how to prevent all function arguments on next line?
我有一個 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);
以下配置是正確的,可以使用 clang-format 5.0 獲得所需的格式。
AlignAfterOpenBracket: AlwaysBreak
AllowAllParametersOfDeclarationOnNextLine: false
BinPackParameters: false
來自類似問題的最高投票答案中的解決方案對我有用,
嘗試設置:
BinPackArguments: false
BinPackParameters: false
並確保
ExperimentalAutoDetectBinPacking: false
AllowAllParametersOfDeclarationOnNextLine: false
或未定義。
我想你需要
AllowAllParametersOfDeclarationOnNextLine: true
除非第一個參數與函數調用在同一行,否則它對我有用,在這種情況下,它將它們全部放在同一行上。
我也有
ExperimentalAutoDetectBinPacking: false
這可能有一些影響?
我正在使用 3.8.0 版。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.