本文介绍了如何在clang格式的函数参数包装和对齐中施加自己的自定义样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接着如何以clang格式对齐函数参数名称?,我想可以做相反的事情.换句话说:

Following on from How can I align function parameter names in clang-format?, 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
}

代替此:

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

前一种可能吗?后者对我来说看起来非常丑陋,只是颠倒了他的答案中的@AhmedFasih的说明链接的问题没有任何作用,至少对我没有帮助:

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:

我正在使用VS Code v1.50.1(系统设置程序),提交d2e414d9e4239a252d1ab117bd7067f125afd80a,其使用的是clang格式v10.0.1.

I'm using VS Code v1.50.1 (system setup), commit d2e414d9e4239a252d1ab117bd7067f125afd80a which uses clang-format v10.0.1.

更新:我刚刚意识到我的评论有些刺耳,因此我应该在此处提供一些背景信息,以鼓励点击进入链接的页面.对于在短时间内任何人冒犯的行为表示歉意.我还应该按照sweenish的建议提供我的 .clang-format ,所以这里是:

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:

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格式文件中.

Add the following setting, AlignAfterOpenBracket: DontAlign, to your .clang-format file.

如果要控制缩进的大小(例如,使用8而不是4),则还需要为 ContinuationIndentWidth 提供一个值.

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.

这篇关于如何在clang格式的函数参数包装和对齐中施加自己的自定义样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 19:00