【问题标题】:How to make clang-format indent extern C blocks in C++?如何在 C++ 中使 clang 格式缩进外部 C 块?
【发布时间】:2017-08-10 16:17:37
【问题描述】:

我只是在学习使用 clang 格式。我主要设法对其进行配置以符合我的口味,但我不知道如何使其缩进 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'

【问题讨论】:

    标签: c++ clang clang-format


    【解决方案1】:

    较新版本的 clang 格式(clang-format-12 或更高版本)确实实现了 IndentExternBlock 标志,(相关)可能值为 NoIndentIndent

    来源:

    【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 感谢您的评论。我尝试过这个。它工作得很好,但它也包裹了我不想要的extern "C" 之后的大括号。有没有办法在不包裹大括号的情况下缩进extern "C" 的内容?
    • 我希望我知道 :) 我也在找这个。
    猜你喜欢
    • 2021-04-28
    • 2014-11-17
    • 2017-08-05
    • 2015-09-29
    • 2019-06-18
    • 1970-01-01
    • 2016-01-20
    • 2016-01-23
    • 1970-01-01
    相关资源
    最近更新 更多