[英]What's clang-format's equivalent to rustfmt's indent_style=Block?
如果 clang-format 是 rustfmt,它將有這個包羅萬象的indent_style配置選項,它指的是縮進樣式的基本區別:
視覺(默認為 clang 格式):
ReturnType<std::vector<int>> ClassName::functionName(int a,
bool b,
float c,
double d,
long double complex e);
static const char* names[] = {"a",
"b",
"c"};
塊(rustfmt 中的默認值):
ReturnType<std::vector<int>> ClassName::functionName(
int a,
bool b,
float c,
double d,
long double complex e);
static const char* names[] = {
"a",
"b",
"c",
};
如何配置 clang-format 以在所有語法范圍內進行塊縮進?
或者是否有任何 C++ 格式化程序支持塊縮進?
默認樣式設置為 Microsoft 樣式(在打開的括號處對齊)。 使用設置為Google
的BasedOnStyle
來獲取塊縮進:
BasedOnStyle: Google
Uncrustify 可以做到這一點,至少就您可以找到 C++ 必須提供的每個可想象的語法 scope 的相應選項而言——我沒有看到任何整體選項。
作為一個開始:
nl_func_def_start_multi_line = true
nl_func_decl_start_multi_line = true
nl_func_call_start_multi_line = true
nl_after_brace_open=true
nl_type_brace_init_lst_open = true
nl_enum_own_lines = add
nl_constr_init_args = add
pos_constr_colon = lead_break
pos_constr_comma = lead_break
可以配置什么:
(涵蓋函數、ctor init 列表和枚舉,但不包括列表)
AlignAfterOpenBracket: AlwaysBreak BreakConstructorInitializers: BeforeComma BinPackArguments: 'false' BinPackParameters: 'false'
BinPack* 選項並不嚴格用於塊縮進,而是像問題所示那樣將一個或所有項目放在同一行。
對於列表,clang-format 在使用后綴逗號的地方使用塊縮進,在使用中綴逗號的地方使用視覺縮進:
static const char* postfixCommaDelimited[] = { "a", "b", "c", }; static const char* infixCommaDelimited[] = {"a", "b", "c"};
如果所有中綴逗號分隔的列表都是單行的,我認為這是有道理的,但我希望 clang-format 可以對多行列表做一些事情。 Rustfmt 將它們重寫為后綴逗號,我也希望在 C++ 中使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.