如何在 clang 格式的函数参数包装和对齐上强加我自己的自定义样式?

How can I impose my own custom style on function parameter wrapping and alignment in clang-format?

之后,我希望能够做相反的事情。换句话说,这个:

void ReallyLongFunctionNameWithLotsOfParams(Type param1, Type param2, Type param3,
    Type param4, Type param5, Type param6, Type param7, Type param8, Type param9) {
    ...function body
}

而不是这个:

void ReallyLongFunctionNameWithLotsOfParams(Type param1, Type param2, Type param3,
                                            Type param4, Type param5, Type param6,
                                            Type param7, Type param8, Type param9) {
    ...function body
}

前者可以吗?后者在我看来非常丑陋,简单地反转@AhmedFasih 在 中的说明没有任何作用,至少对我来说不是:

with BinPackArguments and BinPackParameters both false, and AlignConsecutiveAssignments and AlignConsecutiveDeclarations both set to true (documentation of these parameters).

我正在使用 VS Code v1.50.1(系统设置),提交 d2e414d9e4239a252d1ab117bd7067f125afd80a,它使用 clang-format v10.0.1。

更新:我刚刚意识到我的评论有点苛刻,我应该在这里提供一些背景信息以鼓励点击链接页面。对于在这么短的时间内任何人的冒犯,我们深表歉意。我还应该按照 sweenish 的建议提供我的 .clang-format,所以这里是:

BasedOnStyle:                           Google
AccessModifierOffset:                   -4
AlignConsecutiveDeclarations:           false
AllowShortIfStatementsOnASingleLine:    false
BinPackArguments:                       true
BinPackParameters:                      true
BraceWrapping:
    AfterClass:                         false
    AfterControlStatement:              false
    AfterEnum:                          false
    AfterFunction:                      false
    AfterNamespace:                     false
    AfterObjCDeclaration:               false
    AfterStruct:                        false
    AfterUnion:                         false
    BeforeCatch:                        false
    BeforeElse:                         false
    IndentBraces:                       false
BreakBeforeBraces:                      Custom
ColumnLimit:                            0
IndentCaseLabels:                       true
IndentWidth:                            4
PointerAlignment:                       Left
TabWidth:                               4
UseTab:                                 Always

将以下设置 AlignAfterOpenBracket: DontAlign 添加到您的 .clang-format 文件。

如果您想控制缩进的大小(例如,使用 8 而不是 4),您还需要为 ContinuationIndentWidth.

提供一个值