【发布时间】:2014-04-26 01:56:02
【问题描述】:
我有以下 .cpp 文件:
////////////////////////////////////////////////////////////////////////////////
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;
}
(斜线分隔 80 个字符)。使用以下配置文件,clang-format 建议:
////////////////////////////////////////////////////////////////////////////////
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;
}
即使在文件中,我也允许简短的 if 语句放在一行中。
我是否设置了错误的选项?
我可以使用哪些选项来最大限度地减少浪费的垂直空间?
Clang-format 的 .clang-format 文件
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
【问题讨论】:
-
目前还没有 clang 格式的标签,如果有人可以添加它,我将不胜感激。
-
问题是括号。
if (test) call_function_name(test);但是,是什么让您认为垂直空间被浪费了?垂直空间是需要保护的宝贵资源吗?它不是。顺便说一句,如果它与if位于同一行,那么祝你在调试器中在call_function_name(test)语句中设置一个断点。 -
@DavidHammen 是的,问题似乎在括号中。您是否使用行号放置断点?我从不这样做:/
-
@DavidHammen:垂直空间是宝贵的资源,不用上下翻页就能看到越多,越容易看懂一块(或多块) ) 的代码。
标签: c++ formatting clang clang-format