我成功地設法使我的代碼像我想要的那樣使用 clang 格式格式。
但是,有一件事讓我感到困擾:我希望在結構/類/函式的定義之間和函式的宣告之間有一個空白行。目前,在格式化時,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"
這是它的外觀:

我想要兩個結構之間的空行。
uj5u.com熱心網友回復:
你有
MaxEmptyLinesToKeep: "0"
需要將其設定為1,以確保不洗掉定義之間的多個空行。
重要的是,該值必須是無符號型別,而不是字串。
所以你想要的正確設定應該是
MaxEmptyLinesToKeep: 1
請注意,如果您在定義之間還沒有至少一個空行,這將不起作用,但是從 clang-format 14 開始,您可以使用
SeparateDefinitionBlocks : Always
這將在每個定義之間添加一個空行。其他選項是Leave不更改任何內容的選項,以及Never洗掉空行(如果有)的選項。
我不認為有一個選項可以讓您在以前的版本中執行此操作。
來源:Clang 格式樣式選項。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/412632.html
標籤:
上一篇:多次使用標題是否不好?
