【发布时间】:2021-02-20 16:23:29
【问题描述】:
从How can I align function parameter names 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 在his answer to the linked question 中的说明颠倒过来,至少对我没有任何作用:
BinPackArguments 和 BinPackParameters 都为 false,并且 AlignConsecutiveAssignments 和 AlignConsecutiveDeclarations 都设置为 true(这些参数的文档)。
我正在使用 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
【问题讨论】:
-
BinPackArguments和BinPackParameters。我建议查看文档。 clang.llvm.org/docs/ClangFormatStyleOptions.html -
我已经搜索了文档并尝试了这两个选项。我在上面通过链接另一个问题并说“在他对链接问题的回答中颠倒@AhmedFasih的指示没有任何作用,至少对我而言没有”。 任何人会点击此网站上的链接吗?!
标签: c++ clang clang-format