I'm not sure if this is a limitation or bug with clang-format (built from source, clang-format version 12.0.0 ([email protected]:llvm/llvm-project.git d4ce062340064c3f73b8f6136c7350a5abe83cac)
), but I am unable to disable indentation after extern "C" {
.
My current .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
This example file is the "formatted" result:
#ifdef __cplusplus
extern "C"
{
#endif
void example(void);
#ifdef __cplusplus
}
#endif
but I want something like:
#ifdef __cplusplus
extern "C"
{
#endif
void example(void);
#ifdef __cplusplus
}
#endif
It seems like IndentExternBlock: NoIndent
should be the correct option to force this, but it's still indenting even with that set.
Is it possible that BreakBeforeBraces: Allman
is overriding this setting? I assumed that IndentExternBlock
would override braces unless set to AfterExternBlock
.
question from:
https://stackoverflow.com/questions/65866419/unable-to-disable-extern-indentation-with-clang-format 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…