clang-format堆栈所有if语句参数,如果它们太长 [英] clang-format stack all if-statement arguments if they are too long
问题描述
我有一个if
语句,该语句具有几个or
ed参数.为了便于阅读,我将它们垂直堆叠如下.
I have an if
statement that has several or
ed arguments. I have stacked them vertically as below for readability.
if (health.flag_a ||
health.flag_b ||
health.flag_c ||
health.flag_d ||
health.flag_e ||
health.flag_f ||
health.flag_g ||
health.flag_h ||
health.flag_i ||
health.flag_k) {
do_something();
return false;
}
clang-format
将此转换为:
if (health.flag_a || health.flag_b || health.flag_c || health.flag_d || health.flag_e || health.flag_f || health.flag_g || health.flag_h ||
health.flag_i || health.flag_k) {
do_something();
return false;
}
如果它们不能排成一行,我希望clang-format
像上面那样堆叠它们.
我期望BinPackArguments
做到这一点,但是我没有任何运气.
I want clang-format
to stack them like above if they don't fit on one line.
I expected BinPackArguments
do this, but I'm not having any luck.
这可以实现吗?
请参阅下面的.clang-format
.
感谢您的帮助.
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 145
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 4
UseTab: ForIndentation
...
推荐答案
不直接,但是您可以使用BreakBeforeBinaryOperators
来实现类似目的.尝试将此值设置为NonAssignment
.但是,这会将您的||
运算符放在每个其他条件之前 ,而不是放在它们之后.
Not directly, but you can achieve something like it with BreakBeforeBinaryOperators
. Try setting this value to NonAssignment
. This will put your ||
operators before each additional condition, though, not after them.
这篇关于clang-format堆栈所有if语句参数,如果它们太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!