Skip to content

Commit 60ba5e1

Browse files
authored
Fix outer "elif" with inner "if" (#136)
Fixes #135.
1 parent b3a7395 commit 60ba5e1

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

indent/python.vim

+3-3
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ function! s:find_start_of_block(lnum, types, skip, multiple) abort
158158
else
159159
let re_skip = ''
160160
endif
161-
let lnum = a:lnum
162-
let last_indent = indent(lnum) + 1
161+
let last_indent = indent(a:lnum) + 1
162+
let lnum = a:lnum - 1
163163
while lnum > 0 && last_indent > 0
164164
let indent = indent(lnum)
165165
if indent < last_indent
@@ -260,7 +260,7 @@ function! s:indent_like_block(lnum)
260260
endif
261261

262262
let [blocks, skip] = blocks_ignore
263-
let indents = s:find_start_of_block(a:lnum - 1, blocks, skip, multiple)
263+
let indents = s:find_start_of_block(a:lnum, blocks, skip, multiple)
264264
if empty(indents)
265265
return -1
266266
endif

spec/indent/indent_spec.rb

+20
Original file line numberDiff line numberDiff line change
@@ -774,3 +774,23 @@
774774
indent.should == 4
775775
end
776776
end
777+
778+
describe "elif after two ifs" do
779+
before {
780+
vim.feedkeys '\<ESC>ggdG'
781+
}
782+
783+
it "keeps its indent to the outer if" do
784+
vim.feedkeys 'iif 1:\<CR>if 2:\<CR>pass\<CR>elif 3:\<CR>pass\<CR>'
785+
indent.should == 4
786+
vim.feedkeys '\<Esc>'
787+
indent.should == 0
788+
proposed_indent.should == shiftwidth
789+
vim.feedkeys 'ielif 4:'
790+
indent.should == 0
791+
proposed_indent.should == 0
792+
vim.feedkeys '\<CR>'
793+
indent.should == 4
794+
proposed_indent.should == 4
795+
end
796+
end

0 commit comments

Comments
 (0)