From 2af501b7fedc4a20c7595a02871c28c7b8998014 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johann=20Kl=C3=A4hn?= Date: Fri, 3 Jan 2014 22:52:36 +0100 Subject: [PATCH] unindent 'else' after 'for' and 'try/except' --- indent/python.vim | 3 ++- spec/indent/indent_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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\' -- 2.39.2