[英]How can I impose my own custom style on function parameter wrapping and alignment in clang-format?
Following on from How can I align function parameter names in clang-format?继如何以 clang 格式对齐函数参数名称? , I'd like to be able to do the opposite.
,我希望能够做相反的事情。 In other words, this:
换句话说,这:
void ReallyLongFunctionNameWithLotsOfParams(Type param1, Type param2, Type param3,
Type param4, Type param5, Type param6, Type param7, Type param8, Type param9) {
...function body
}
Instead of this:取而代之的是:
void ReallyLongFunctionNameWithLotsOfParams(Type param1, Type param2, Type param3,
Type param4, Type param5, Type param6,
Type param7, Type param8, Type param9) {
...function body
}
Is the former possible?前者可能吗? The latter looks incredibly ugly to me and simply inversing @AhmedFasih's instructions in his answer to the linked question does nothing, at least not for me:
后者对我来说看起来非常丑陋,并且在他对链接问题的回答中简单地反转@AhmedFasih 的说明没有任何作用,至少对我来说不是:
with BinPackArguments and BinPackParameters both false, and AlignConsecutiveAssignments and AlignConsecutiveDeclarations both set to true (documentation of these parameters).
BinPackArguments 和 BinPackParameters 均为 false,AlignConsecutiveAssignments 和 AlignConsecutiveDeclarations 均设置为 true(这些参数的文档)。
I'm using VS Code v1.50.1 (system setup), commit d2e414d9e4239a252d1ab117bd7067f125afd80a which uses clang-format v10.0.1.我正在使用 VS Code v1.50.1(系统设置),提交 d2e414d9e4239a252d1ab117bd7067f125afd80a,它使用 clang 格式 v10.0.1。
Update : I just realised my comment was a little harsh, and that I should provide some context here to encourage clicking through to the linked page.更新:我刚刚意识到我的评论有点苛刻,我应该在此处提供一些上下文以鼓励点击链接页面。 Apologies for any offence taken by anyone in this short time.
对任何人在这短时间内所犯的任何罪行表示歉意。 I should also provide my
.clang-format
as suggested by sweenish, so here it is:我还应该
.clang-format
建议提供我的.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
Add the following setting, AlignAfterOpenBracket: DontAlign
, to your .clang-format file.将以下设置
AlignAfterOpenBracket: DontAlign
添加到您的 .clang 格式文件中。
If you want to control the size of the indent (for example, using 8 instead of 4), you would also need to provide a value to ContinuationIndentWidth
.如果您想控制缩进的大小(例如,使用 8 而不是 4),您还需要为
ContinuationIndentWidth
提供一个值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.