如何在C ++中使用clang-format缩进extern C块?

时间:2017-08-10 16:17:37

标签: c++ clang clang-format

我只是学习使用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'

2 个答案:

答案 0 :(得分:1)

更新版本的clang-format(我相信它是在LLVM 6中引入的)确实为BraceWrapping配置选项实现了AfterExternBlock标志。考虑将其设置为true。

答案 1 :(得分:1)

较新版本的 clang-format(clang-format-10 或更高版本)确实实现了 IndentExternBlock 标志