From 60ba5e11a61618c0344e2db190210145083c91f8 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 20 Mar 2020 16:19:55 +0100 Subject: [PATCH] Fix outer "elif" with inner "if" (#136) Fixes https://github.com/Vimjas/vim-python-pep8-indent/issues/135. --- indent/python.vim | 6 +++--- spec/indent/indent_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) 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 -- 2.39.5