From: Johann Klähn Date: Fri, 3 Jan 2014 21:52:36 +0000 (+0100) Subject: unindent 'else' after 'for' and 'try/except' X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/2af501b7fedc4a20c7595a02871c28c7b8998014?ds=sidebyside;hp=--cc unindent 'else' after 'for' and 'try/except' --- 2af501b7fedc4a20c7595a02871c28c7b8998014 diff --git a/indent/python.vim b/indent/python.vim index 6fb1889..9b8e9b1 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -19,7 +19,8 @@ setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif,=except let s:maxoff = 50 let s:block_rules = { - \ '^\s*\(elif\|else\)\>': ['if', 'elif'], + \ '^\s*elif\>': ['if', 'elif'], + \ '^\s*else\>': ['if', 'elif', 'for', 'try', 'except'], \ '^\s*except\>': ['try', 'except'], \ '^\s*finally\>': ['try', 'except', 'else'] \ } diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index 4652ef9..db7a49c 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -100,6 +100,18 @@ shared_examples_for "vim" do end end + describe "when writing an 'else' block" do + it "aligns to the preceeding 'for' block" do + vim.feedkeys 'ifor x in "abc":\pass\else:' + indent.should == 0 + end + + it "aligns to the preceeding 'if' block" do + vim.feedkeys 'ifor x in "abc":\if True:\pass\else:' + indent.should == shiftwidth + end + end + describe "when using parens and control statements" do it "avoids ambiguity by using extra indentation" do vim.feedkeys 'iif (111 and\'