Clang格式将语句正文拆分为多行 [英] Clang format splits if statement body into multiple lines
本文介绍了Clang格式将语句正文拆分为多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的.cpp文件:
/////////////// ////////////////////////////////////////////////// // b
$ void call_long_function_name(bool){}
void sf(bool){}
int main(){
布尔测试=真;
if(test){call_function_name(test); }
if(test){sf(test); }
返回0;
$ / code $ / pre
$ b $ p $(斜杠分隔80个字符)。使用以下配置文件,clang格式表明: /////////////// ////////////////////////////////////////////////// // b
$ void call_long_function_name(bool){}
void sf(bool){}
int main(){
布尔测试=真;
if(test){
call_function_name(test);
}
if(test){
sf(test);
}
return 0;
即使在文件中,我也允许使用简短的语句来适合单行。
-
我是否设置了错误的选项?我可以使用哪些选项来最小化浪费的垂直空间?
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ :true
AlwaysBreakBeforeMultilineStrings:false
AlwaysBreakTemplateDeclarations:false
BinPackParameters:true
BreakBeforeBinaryOperators:true
AllowShortFunctionsOnASingleLine:true
AllowShortIfStatementsOnASingleLine:true
AllowShortLoopsOnASingleLine: true
BreakBeforeBraces:Attach
BreakBeforeTernaryOperators:true
BreakConstructorInitializersBeforeComma:true
ColumnLimit:80
ConstructorInitializerAllOnOneLineOrOnePerLine:true
ConstructorInitializerIndentWidth:2
ContinuationIndentWidth:0
Cpp11BracedListStyle:
IndentCaseLabels:true
IndentFunctionDeclarationAfterType:true
IndentWidth:2
MaxEmptyLinesToKeep:1
命名空间的缩进:无
PointerBindsToType:true
SpaceAfterControlStatementKeyword:true
SpaceBeforeAssignmentOperators:true
SpaceInEmptyParentheses:false
SpacesBeforeTrailingComments:2
SpacesInCStyleCastParentheses:false
SpacesInParentheses:false
SpacesInAngles:false
标准:cpp11
TabWidth:2
UseTab:从不
解决方案更新版本的clang格式有一个额外的选项AllowShortBlocksOnASingleLine,它控制了这种行为。
I have the following .cpp file:
////////////////////////////////////////////////////////////////////////////////
void call_long_function_name(bool) {}
void sf(bool) {}
int main() {
bool test = true;
if (test) { call_function_name(test); }
if (test) { sf(test); }
return 0;
}
(the slashes delimit 80 characters). Using the following configuration file, clang-format suggests:
////////////////////////////////////////////////////////////////////////////////
void call_long_function_name(bool) {}
void sf(bool) {}
int main() {
bool test = true;
if (test) {
call_function_name(test);
}
if (test) {
sf(test);
}
return 0;
}
even tho in the file I allow short if statements to fit into a single line.
Did I set any options wrong?
Which options can I use to minimize wasted vertical space?
Clang-format's .clang-format file
BasedOnStyle: Google
AccessModifierOffset: -1
AlignEscapedNewlinesLeft: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackParameters: true
BreakBeforeBinaryOperators: true
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
ColumnLimit: 80
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 0
Cpp11BracedListStyle: true
DerivePointerBinding: true
IndentCaseLabels: true
IndentFunctionDeclarationAfterType: true
IndentWidth: 2
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PointerBindsToType: true
SpaceAfterControlStatementKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInAngles: false
Standard: Cpp11
TabWidth: 2
UseTab: Never
解决方案 Newer versions of clang-format have an additional option "AllowShortBlocksOnASingleLine", which controls this behavior.
这篇关于Clang格式将语句正文拆分为多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文