我成功地将我的代码设置为 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"
Run Code Online (Sandbox Code Playgroud)
它看起来是这样的:
我想要两个结构之间有一个空行。
cig*_*ien 10
你有
MaxEmptyLinesToKeep: "0"
Run Code Online (Sandbox Code Playgroud)
需要设置1为,以确保定义之间的多个空行不会被删除。
重要的是,该值必须是无符号类型,而不是字符串。
所以你想要的正确设置应该是
MaxEmptyLinesToKeep: 1
Run Code Online (Sandbox Code Playgroud)
请注意,如果定义之间还没有至少一个空行,则这将不起作用,但从 clang-format 14 开始,您可以使用
SeparateDefinitionBlocks : Always
Run Code Online (Sandbox Code Playgroud)
这将在每个定义之间添加一个空行。其他选项是Leave不更改任何内容的选项,以及Never将删除空行(如果有)的选项。
我认为在以前的版本中没有可以让您执行此操作的选项。
来源:Clang 格式样式选项。
| 归档时间: |
|
| 查看次数: |
2003 次 |
| 最近记录: |