2016-12-08 55 views
0

就像下面的代碼,我用鐺格式的自動格式代碼我clang-format如何不將if語句放入一行?

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語句到oneline?

我的問題是不是因爲這個問題(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 
+2

'AllowShortBlocksOnASingleLine'?這裏是你可能的重複:[**鏗鏘聲格式將聲明正文拆分爲多行**](http://stackoverflow.com/questions/22512344/clang-format-splits-if-statement-body-into-multiple-行) –

+1

也可以在代碼塊之前使用'// clang-format off'命令,然後在塊之後使用'// clang-format on',這樣就不會讓您的塊被'clang'格式化。所以你自己格式化它,並從自動化格式中排除它。這裏是你可能的重複(第二個答案):[** lang-format line break **](http://stackoverflow.com/questions/33656800/clang-format-line-breaks) –

+0

@FirstStep AllowShortBlocksOnASingleLine將不起作用和評論 - 如果陳述過於冗長,我會繼續尋找解決方案 – user392412

回答