我想使用clang-format,但它始终以returnType之后的新行开头。我阅读了文档并尝试了
“AlwaysBreakAfterReturnType:无”
但这种接缝无效。我在QT创建者的ubuntu 17.10中使用了clang-format 6.0。
是:
int
main() {
...
}
预期:
int main() {
...
}
版本:clang-format 6.0,clang-format配置文件:
BasedOnStyle: Mozilla
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments : true
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: true
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakStringLiterals : false
ColumnLimit: 120
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: true
IndentCaseLabels: false
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword : false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 3
SpacesInAngles: false
SpacesInCStyleCastParentheses: true
SpacesInContainerLiterals: true
SpacesInParentheses: true
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
有什么想法吗?
答案 0 :(得分:0)
我无法在您提供的最小示例中重现您的问题:
$ cat .clang-format
BasedOnStyle: Mozilla
AlwaysBreakAfterReturnType: None
$ cat main.c
int main() {
return 0;
}
$ clang-format main.c
int
main()
{
return 0;
}
$ clang-format --version
clang-format version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
实际上,您还设置了IndentWrappedFunctionNames
,其行为正是您获得的行为。如果您不想要此行为,请不要设置IndentWrappedFunctionNames
。
答案 1 :(得分:0)
您应该仔细阅读文档:
RTBS_None(在配置中:无)返回类型后中断 自动。考虑到PenaltyReturnTypeOnItsOwnLine。
因此,“无”并不意味着它在返回类型之后就不会中断,它会考虑到BinPackParameters
,BraceWrapping
等其他设置及其惩罚。
要使返回类型后出现中断的可能性较小或“几乎”关闭,可以将PenaltyReturnTypeOnItsOwnLine
设置为很高的值,例如:
PenaltyReturnTypeOnItsOwnLine: 1000000
请注意,我对罚款数字到底是什么意思,它们如何相互关联以及如何计算最后的换行符并不熟悉。您将不得不在其他地方找到该信息(clang格式的源代码?)。
答案 2 :(得分:0)
只需尝试将已弃用的属性“ AlwaysBreakAfterDefinitionReturnType”也分配为“无”。
这对我来说很好。
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None