如何在 C++ 中制作 clang 格式缩进外部 C 块?
How to make clang-format indent extern C blocks in C++?
我刚开始学习使用 clang-format。我主要设法配置它以符合我的口味,但我不知道如何让它缩进 extern "C"
块。
这是期望的结果:
extern "C" {
void myFunction() {
// ...
}
}
但这就是我得到的:
extern "C" {
void myFunction() {
// ...
}
}
这是我的配置:
BasedOnStyle: 'LLVM'
IndentWidth: 4
AccessModifierOffset: -4
AlignAfterOpenBracket: 'false'
AlignConsecutiveAssignments: 'false'
AlignConsecutiveDeclarations: 'false'
AlignEscapedNewlinesLeft: 'true'
AlignOperands: 'true'
AlignTrailingComments: 'true'
AllowAllParametersOfDeclarationOnNextLine: 'true'
AllowShortBlocksOnASingleLine: 'false'
AllowShortCaseLabelsOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: 'true'
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakAfterDefinitionReturnType: 'None'
AlwaysBreakAfterReturnType: 'None'
AlwaysBreakBeforeMultilineStrings: 'false'
AlwaysBreakTemplateDeclarations: 'true'
BinPackArguments: 'true'
BinPackParameters: 'true'
BreakBeforeBraces: 'Custom'
BreakBeforeTernaryOperators: false
BraceWrapping: {
AfterClass: 'false'
AfterControlStatement: 'false'
AfterEnum: 'false'
AfterFunction: 'false'
AfterNamespace: 'false'
AfterStruct: 'false'
AfterUnion: 'false'
BeforeCatch: 'true'
BeforeElse: 'true'
IndentBraces: 'false'
}
BreakConstructorInitializersBeforeComma: 'false'
BreakStringLiterals: 'false'
ColumnLimit: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
DerivePointerAlignment: 'false'
KeepEmptyLinesAtTheStartOfBlocks: 'true'
MaxEmptyLinesToKeep: 1
NamespaceIndentation: 'All'
PointerAlignment: 'Right'
ReflowComments: 'false'
SortIncludes: 'false'
SpaceAfterCStyleCast: 'true'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeParens: 'ControlStatements'
SpaceInEmptyParentheses: 'false'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'true'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
Standard: 'Cpp11'
TabWidth: 4
UseTab: 'Never'
较新版本的 clang-format(我相信它是在 LLVM 6 中引入的)确实为 BraceWrapping 配置选项实现了 AfterExternBlock 标志。考虑将其设置为 true。
较新版本的 clang-format(clang-format-12
或更高版本)确实使用 NoIndent
和 Indent
的(相关)可能值实现 IndentExternBlock
标志。
来源:
我刚开始学习使用 clang-format。我主要设法配置它以符合我的口味,但我不知道如何让它缩进 extern "C"
块。
这是期望的结果:
extern "C" {
void myFunction() {
// ...
}
}
但这就是我得到的:
extern "C" {
void myFunction() {
// ...
}
}
这是我的配置:
BasedOnStyle: 'LLVM'
IndentWidth: 4
AccessModifierOffset: -4
AlignAfterOpenBracket: 'false'
AlignConsecutiveAssignments: 'false'
AlignConsecutiveDeclarations: 'false'
AlignEscapedNewlinesLeft: 'true'
AlignOperands: 'true'
AlignTrailingComments: 'true'
AllowAllParametersOfDeclarationOnNextLine: 'true'
AllowShortBlocksOnASingleLine: 'false'
AllowShortCaseLabelsOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: 'true'
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakAfterDefinitionReturnType: 'None'
AlwaysBreakAfterReturnType: 'None'
AlwaysBreakBeforeMultilineStrings: 'false'
AlwaysBreakTemplateDeclarations: 'true'
BinPackArguments: 'true'
BinPackParameters: 'true'
BreakBeforeBraces: 'Custom'
BreakBeforeTernaryOperators: false
BraceWrapping: {
AfterClass: 'false'
AfterControlStatement: 'false'
AfterEnum: 'false'
AfterFunction: 'false'
AfterNamespace: 'false'
AfterStruct: 'false'
AfterUnion: 'false'
BeforeCatch: 'true'
BeforeElse: 'true'
IndentBraces: 'false'
}
BreakConstructorInitializersBeforeComma: 'false'
BreakStringLiterals: 'false'
ColumnLimit: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
DerivePointerAlignment: 'false'
KeepEmptyLinesAtTheStartOfBlocks: 'true'
MaxEmptyLinesToKeep: 1
NamespaceIndentation: 'All'
PointerAlignment: 'Right'
ReflowComments: 'false'
SortIncludes: 'false'
SpaceAfterCStyleCast: 'true'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeParens: 'ControlStatements'
SpaceInEmptyParentheses: 'false'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'true'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
Standard: 'Cpp11'
TabWidth: 4
UseTab: 'Never'
较新版本的 clang-format(我相信它是在 LLVM 6 中引入的)确实为 BraceWrapping 配置选项实现了 AfterExternBlock 标志。考虑将其设置为 true。
较新版本的 clang-format(clang-format-12
或更高版本)确实使用 NoIndent
和 Indent
的(相关)可能值实现 IndentExternBlock
标志。