2

Just like the code below, I use clang-format to automatic format my codes

if(detectBeats[*beatsCont-2] > detectBeats[*beatsCont-1]
   || fabs(detectBeats[*beatsCont-2] > detectBeats[*beatsCont-1]) < 1.0)
{
    *beatsCont -=1;
}

Whatever I set the .clang-formt file, it always formatted like this:

if(detectBeats[*beatsCont-2] > detectBeats[*beatsCont-1] || fabs(detectBeats[*beatsCont-2] > detectBeats[*beatsCont-1]) < 1.0)
{
    *beatsCont -=1;
}

How can I set the rules not wrap the if statements into oneline?

My question isn't as that question(Clang format splits if statement body into multiple lines), b/c my if statement wrapped, not the body

Here is my .clang-format file

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
Community
  • 1
  • 1
user392412
  • 743
  • 12
  • 18
  • 3
    `AllowShortBlocksOnASingleLine`? Here is your possible duplicate: [**Clang format splits if statement body into multiple lines**](http://stackoverflow.com/questions/22512344/clang-format-splits-if-statement-body-into-multiple-lines) – Khalil Khalaf Dec 08 '16 at 06:49
  • 2
    Also you could use the `// clang-format off` command before a block of code, then `// clang-format on` after the block, and that will exclude your block from getting formatted by `clang`. So you format it yourself and exclude it from the automated formating. Here is your possible duplicate (second answer): [**lang-format line breaks**](http://stackoverflow.com/questions/33656800/clang-format-line-breaks) – Khalil Khalaf Dec 08 '16 at 06:55
  • @FirstStep AllowShortBlocksOnASingleLine won't work, and comments-way for every if statements is too verbose, I'll keep looking solutions – user392412 Dec 10 '16 at 04:15

1 Answers1

1

You need to use ColumnLimit. Doc here. More method here

Community
  • 1
  • 1
Stargateur
  • 24,473
  • 8
  • 65
  • 91
  • 4
    `ColumnLimit` is a global property. It can't prevent short manually wrapped lines from combining and leave long lines as-is. – Mark Jeronimus Jul 19 '20 at 18:09