【发布时间】:2021-04-28 04:12:25
【问题描述】:
我不确定这是否是 clang 格式的限制或错误(从源代码构建,clang-format version 12.0.0 (git@github.com:llvm/llvm-project.git d4ce062340064c3f73b8f6136c7350a5abe83cac)),但我无法在 extern "C" { 之后禁用缩进。
我现在的.clang-format:
Language: Cpp
Standard: Latest
UseTab: Never
IndentWidth: 4
AccessModifierOffset: -2
SpaceBeforeParens: Never
ColumnLimit: 80
SpacesBeforeTrailingComments: 1
BreakBeforeBraces: Allman
FixNamespaceComments: true
SortIncludes: true
SortUsingDeclarations: true
IncludeBlocks: Regroup
IndentPPDirectives: AfterHash
IndentCaseLabels: true
IndentExternBlock: NoIndent
NamespaceIndentation: All
AlignTrailingComments: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignConsecutiveBitFields: true
AlignConsecutiveMacros: true
AlignAfterOpenBracket: AlwaysBreak
AllowShortFunctionsOnASingleLine: None
AllowShortBlocksOnASingleLine: Never
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortLambdasOnASingleLine: None
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
PenaltyBreakBeforeFirstCallParameter: 500 # basically always break
# Note: must have my custom build (https://github.com/jasperswallen/llvm-project/tree/pointeralignment-right) to properly enable these options
BreakBeforeConceptDeclarations: true
PointerAlignment: Right
这个示例文件是“格式化”的结果:
#ifdef __cplusplus
extern "C"
{
#endif
void example(void);
#ifdef __cplusplus
}
#endif
但我想要类似的东西:
#ifdef __cplusplus
extern "C"
{
#endif
void example(void);
#ifdef __cplusplus
}
#endif
似乎IndentExternBlock: NoIndent 应该是强制执行此操作的正确选项,但即使使用该设置,它仍会缩进。
BreakBeforeBraces: Allman 是否有可能覆盖此设置?我假设IndentExternBlock 会覆盖大括号,除非设置为AfterExternBlock。
【问题讨论】:
标签: c++ clang-format