Lef*_*ris 9 clang clang-format
clang-format有2个叫做BinPackParameters
和的
选项BinPackArguments
.它们似乎控制着函数声明和函数调用的缩进方式.
BinPackParameters
似乎提供了函数声明的预期结果,但BinPackArguments
似乎没有像函数调用那样工作.
这是一个简单的测试文件:
#include <stdbool.h>
void function_with_a_huge_name_that_should_just_not_be(unsigned int a, char *b, unsigned int c, unsigned int d, unsigned int e)
{
return;
}
int main()
{
function_with_a_huge_name_that_should_just_not_be(13, "bb", 1234234, 4324324, 2355345);
}
Run Code Online (Sandbox Code Playgroud)
这就是它的格式:
#include <stdbool.h>
void function_with_a_huge_name_that_should_just_not_be(unsigned int a,
char *b,
unsigned int c,
unsigned int d,
unsigned int e)
{
return;
}
int main()
{
function_with_a_huge_name_that_should_just_not_be(
13, "bb", 1234234, 4324324, 2355345);
}
Run Code Online (Sandbox Code Playgroud)
我的.clang-format
文件如下:
---
AccessModifierOffset: -2
AlignAfterOpenBracket: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AlwaysBreakAfterDefinitionReturnType: false
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackParameters: false
BinPackArguments: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Linux
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
IndentFunctionDeclarationAfterType: false
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 4
UseTab: Never
Run Code Online (Sandbox Code Playgroud)
我的clang格式版本是: 3.6.0 (tags/RELEASE_360/final)
有了这两个BinPackParameters
并且BinPackArguments
为假,我本来希望得到函数调用的相同缩进,因为我得到了函数声明.
知道我做错了什么吗?
我不认为你做错了什么。发生的情况是 clang-format 意识到您调用该函数的行比您的列限制(设置中的 80 个字符)长。您的AlignAfterOpenBracket
设置为 false,因此 clang-format 将参数放在新行上(请注意,AlignAfterOpenBracket
在 clang-format 的更高版本中获得了额外的可能性)。
您已将这两个BinPack...
设置设置为 false,但是还有一个附加设置可以控制函数声明与函数调用AllowAllParametersOfDeclarationOnNextLine
(在示例中设置为 false)。对于函数声明,如果所有参数不与函数名称位于同一行,这将导致所有参数位于单独的行上。对于函数调用没有相应的设置。
在您的情况下,您提供给函数的参数放置在函数名称之后的下一行。第二行的长度 < 80,因此 clang-format 不再对其执行任何操作。如果参数行比列限制长,clang-format 会将它们放在单独的行上。
所以答案是,从版本 3.9 开始,如果每个参数适合一行,则无法配置 clang-format 将每个参数放在单独的行上。
小智 1
尝试设置ColumnLimit
为 0。看起来此选项“覆盖”或具有比BinPackParameters
和BinPackArguments
选项更高的优先级。
归档时间: |
|
查看次数: |
3089 次 |
最近记录: |