From: Daniel Hahler Date: Fri, 20 Mar 2020 15:19:55 +0000 (+0100) Subject: Fix outer "elif" with inner "if" (#136) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/60ba5e11a61618c0344e2db190210145083c91f8?ds=sidebyside;hp=--cc Fix outer "elif" with inner "if" (#136) Fixes https://github.com/Vimjas/vim-python-pep8-indent/issues/135. --- 60ba5e11a61618c0344e2db190210145083c91f8 diff --git a/indent/python.vim b/indent/python.vim index aca216e..047ae3d 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -158,8 +158,8 @@ function! s:find_start_of_block(lnum, types, skip, multiple) abort else let re_skip = '' endif - let lnum = a:lnum - let last_indent = indent(lnum) + 1 + let last_indent = indent(a:lnum) + 1 + let lnum = a:lnum - 1 while lnum > 0 && last_indent > 0 let indent = indent(lnum) if indent < last_indent @@ -260,7 +260,7 @@ function! s:indent_like_block(lnum) endif let [blocks, skip] = blocks_ignore - let indents = s:find_start_of_block(a:lnum - 1, blocks, skip, multiple) + let indents = s:find_start_of_block(a:lnum, blocks, skip, multiple) if empty(indents) return -1 endif diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index 55e2fba..745e939 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -774,3 +774,23 @@ describe "elif after else" do indent.should == 4 end end + +describe "elif after two ifs" do + before { + vim.feedkeys '\ggdG' + } + + it "keeps its indent to the outer if" do + vim.feedkeys 'iif 1:\if 2:\pass\elif 3:\pass\' + indent.should == 4 + vim.feedkeys '\' + indent.should == 0 + proposed_indent.should == shiftwidth + vim.feedkeys 'ielif 4:' + indent.should == 0 + proposed_indent.should == 0 + vim.feedkeys '\' + indent.should == 4 + proposed_indent.should == 4 + end +end