我成功地将我的代码设置为 clang-format 格式,就像 iIwant 一样。然而,有一点让我很困扰:
我想要在结构/类/函数的定义之间以及函数的声明之间有一个空行。目前,在格式化时,clang-format 会删除空行,从而使所有内容都变得简洁。
这是我的文件:
---
AlignAfterOpenBracket: DontAlign
AlignTrailingComments: "true"
AllowAllArgumentsOnNextLine: "false"
AllowAllConstructorInitializersOnNextLine: "true"
AllowAllParametersOfDeclarationOnNextLine: "false"
AllowShortBlocksOnASingleLine: "false"
AllowShortCaseLabelsOnASingleLine: "false"
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: None
AllowShortLoopsOnASingleLine: "false"
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: "false"
AlwaysBreakTemplateDeclarations: "Yes"
BinPackArguments: "true"
BinPackParameters: "true"
BreakBeforeTernaryOperators: "false"
BreakConstructorInitializers: AfterColon
BreakInheritanceList: AfterColon
ColumnLimit: "170"
CompactNamespaces: "false"
ConstructorInitializerAllOnOneLineOrOnePerLine: "true"
IncludeBlocks: Merge
IndentCaseLabels: "true"
IndentPPDirectives: BeforeHash
IndentWidth: "4"
IndentWrappedFunctionNames: "false"
KeepEmptyLinesAtTheStartOfBlocks: "false"
Language: Cpp
MaxEmptyLinesToKeep: "0"
NamespaceIndentation: All
PointerAlignment: Left
SortIncludes: "true"
SortUsingDeclarations: "true"
SpaceAfterCStyleCast: "false"
SpaceAfterLogicalNot: "false"
SpaceAfterTemplateKeyword: "false"
SpaceBeforeAssignmentOperators: "true"
SpaceBeforeCpp11BracedList: "false"
SpaceBeforeCtorInitializerColon: "false"
SpaceBeforeInheritanceColon: "false"
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: "false"
SpaceInEmptyParentheses: "false"
SpacesBeforeTrailingComments: "3"
SpacesInAngles: "false"
SpacesInCStyleCastParentheses: "false"
SpacesInContainerLiterals: "false"
SpacesInParentheses: "false"
SpacesInSquareBrackets: "false"
Standard: Auto
UseTab: Always
TabWidth: "4"
它看起来是这样的:
我想要两个结构之间有一个空行。
You have
MaxEmptyLinesToKeep: "0"
需要设置为1
相反,以确保定义之间的多个空行不会被删除。
重要的是,该值必须是无符号类型,而不是字符串。
所以你想要的正确设置应该是
MaxEmptyLinesToKeep: 1
请注意,如果定义之间还没有至少一个空行,则这将不起作用,但从 clang-format 14 开始,您可以使用
SeparateDefinitionBlocks : Always
这将在每个定义之间添加一个空行。其他选项是Leave
这不会改变任何东西,并且Never
,这将删除空白行(如果有)。
我认为在以前的版本中没有可以让您执行此操作的选项。
Source: Clang 格式样式选项 https://clang.llvm.org/docs/ClangFormatStyleOptions.html.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)