【发布时间】:2017-04-23 08:04:36
【问题描述】:
就像下面的代码一样,我使用 clang-format 来自动格式化我的代码
if(detectBeats[*beatsCont-2] > detectBeats[*beatsCont-1]
|| fabs(detectBeats[*beatsCont-2] > detectBeats[*beatsCont-1]) < 1.0)
{
*beatsCont -=1;
}
无论我设置什么 .clang-formt 文件,它的格式总是如下:
if(detectBeats[*beatsCont-2] > detectBeats[*beatsCont-1] || fabs(detectBeats[*beatsCont-2] > detectBeats[*beatsCont-1]) < 1.0)
{
*beatsCont -=1;
}
如何设置不将 if 语句包装成单行的规则?
我的问题不是那个问题(Clang format splits if statement body into multiple lines),b/c 我的 if 语句已包装,而不是正文
这是我的 .clang 格式文件
AccessModifierOffset : -4
AllowAllParametersOfDeclarationOnNextLine : false
AlignEscapedNewlinesLeft : false
AlignOperands: true
AlignTrailingComments : true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine : true
AllowShortLoopsOnASingleLine: true
BinPackArguments : false
BinPackParameters : false
BreakBeforeBraces : Linux
ColumnLimit: 0
CommentPragmas: '^ *\/\/'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
IndentWidth : 4
KeepEmptyLinesAtTheStartOfBlocks : false
Language : Cpp
MaxEmptyLinesToKeep : 2
ObjCBlockIndentWidth : 2
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList : false
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators : true
SpaceBeforeParens : ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments : 1
SpacesInAngles: false
SpacesInContainerLiterals : false
SpacesInParentheses : false
SpacesInSquareBrackets: false
Standard: Cpp11
UseTab : Never
【问题讨论】:
-
AllowShortBlocksOnASingleLine?这是您可能的重复:Clang format splits if statement body into multiple lines -
您也可以在代码块之前使用
// clang-format off命令,然后在代码块之后使用// clang-format on,这样您的代码块就不会被clang格式化。因此,您自己格式化并将其从自动格式化中排除。这是您可能的重复(第二个答案):lang-format line breaks -
@FirstStep AllowShortBlocksOnASingleLine 不起作用,并且每个 if 语句的 cmets-way 都过于冗长,我会继续寻找解决方案
标签: c++ clang-format