From: Daniel Hahler Date: Thu, 26 Jul 2018 08:03:04 +0000 (+0200) Subject: Merge pull request #112 from blueyed/fix-97 X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/7665325e833a60a9217f7e62c37069ef6b359d18?hp=b0d020f899c720469eaea8bfe50e71285ad053e6 Merge pull request #112 from blueyed/fix-97 Fix indenting of "else" with outer if --- diff --git a/indent/python.vim b/indent/python.vim index 8444a22..c56c2dc 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -138,27 +138,21 @@ endfunction " Find possible indent(s) of the block starter that matches the current line. function! s:find_start_of_block(lnum, types, multiple) let r = [] - let types = copy(a:types) let re = '\V\^\s\*\('.join(a:types, '\|').'\)\>' let lnum = a:lnum let last_indent = indent(lnum) + 1 while lnum > 0 && last_indent > 0 let indent = indent(lnum) if indent < last_indent - for type in types - let re = '\v^\s*'.type.'>' - if getline(lnum) =~# re - if !a:multiple - return [indent] - endif - if index(r, indent) == -1 - let r += [indent] - endif - " Remove any handled type, e.g. 'if'. - call remove(types, index(types, type)) + if getline(lnum) =~# re + if !a:multiple + return [indent] endif - endfor - let last_indent = indent(lnum) + if index(r, indent) == -1 + let r += [indent] + endif + let last_indent = indent + endif endif let lnum = prevnonblank(lnum - 1) endwhile diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index e60da62..400ec11 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -401,10 +401,22 @@ shared_examples_for "vim" do end describe "when an else is used inside of a nested if" do - before { vim.feedkeys 'iif foo:\\if bar:\\\pass\' } - it "indents an else to the inner if" do + before { vim.feedkeys 'iif foo:\if bar:\pass\' } + it "indents the else to the inner if" do vim.feedkeys 'else:' - indent.should == shiftwidth * 2 + indent.should == shiftwidth + end + end + + describe "when an else is used outside of a nested if" do + before { vim.feedkeys 'iif True:\if True:\pass\\0' } + it "indents the else to the outer if" do + indent.should == 0 + proposed_indent.should == shiftwidth + + vim.feedkeys 'ielse:' + indent.should == 0 + proposed_indent.should == 0 end end