Merge pull request #601 from thorbenk/chains_tabbed_indent

Chains tabbed indent
This commit is contained in:
Marcus Klaas de Vries 2015-11-14 22:00:11 +01:00
commit de599015de
8 changed files with 55 additions and 1 deletions

View File

@ -56,7 +56,15 @@ pub fn rewrite_chain(mut expr: &ast::Expr,
} else if is_block_expr(parent, &parent_rewrite) {
(parent_block_indent, false)
} else {
(offset + Indent::new(context.config.tab_spaces, 0), false)
match context.config.chain_indent {
BlockIndentStyle::Inherit => (context.block_indent, false),
BlockIndentStyle::Tabbed => {
(context.block_indent.block_indent(context.config), false)
}
BlockIndentStyle::Visual => {
(offset + Indent::new(context.config.tab_spaces, 0), false)
}
}
};
let max_width = try_opt!((width + offset.width()).checked_sub(indent.width()));

View File

@ -294,6 +294,7 @@ create_config! {
report_fixme: ReportTactic, ReportTactic::Never,
"Report all, none or unnumbered occurrences of FIXME in source file comments";
chain_base_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indent on chain base";
chain_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indentation of chain";
reorder_imports: bool, false, "Reorder import statements alphabetically";
single_line_if_else: bool, false, "Put else on same line as closing brace for if statements";
format_strings: bool, true, "Format string literals, or leave as is";

View File

@ -0,0 +1,5 @@
// rustfmt-chain_indent: Inherit
fn test() {
let x = my_long_function().my_even_longer_function().my_nested_function().some_random_name().another_function().do_it();
}

View File

@ -0,0 +1,5 @@
// rustfmt-chain_indent: Tabbed
fn test() {
let x = my_long_function().my_even_longer_function().my_nested_function().some_random_name().another_function().do_it();
}

View File

@ -0,0 +1,5 @@
// rustfmt-chain_indent: Visual
fn test() {
let x = my_long_function().my_even_longer_function().my_nested_function().some_random_name().another_function().do_it();
}

View File

@ -0,0 +1,10 @@
// rustfmt-chain_indent: Inherit
fn test() {
let x = my_long_function()
.my_even_longer_function()
.my_nested_function()
.some_random_name()
.another_function()
.do_it();
}

View File

@ -0,0 +1,10 @@
// rustfmt-chain_indent: Tabbed
fn test() {
let x = my_long_function()
.my_even_longer_function()
.my_nested_function()
.some_random_name()
.another_function()
.do_it();
}

View File

@ -0,0 +1,10 @@
// rustfmt-chain_indent: Visual
fn test() {
let x = my_long_function()
.my_even_longer_function()
.my_nested_function()
.some_random_name()
.another_function()
.do_it();
}