From: Hassan Kibirige Date: Sat, 22 Mar 2014 21:55:20 +0000 (-0500) Subject: Make fix work even with of preceeding empty lines. X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/4224ee71e4cdbfa8ef08a59b0db62d915af1b0b6?hp=--cc Make fix work even with of preceeding empty lines. Previous commit was not robust enough to catch the same issue if there were empty lines between the current line the previous block. --- 4224ee71e4cdbfa8ef08a59b0db62d915af1b0b6 diff --git a/indent/python.vim b/indent/python.vim index 177b8ad..461e962 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -179,7 +179,7 @@ function! s:indent_like_previous_line(lnum) let text = getline(lnum) let start = s:find_start_of_multiline_statement(lnum) let base = indent(start) - let current = indent(lnum + 1) + let current = indent(a:lnum) " Jump to last character in previous line. call cursor(lnum, len(text)) @@ -218,7 +218,7 @@ function! s:indent_like_previous_line(lnum) " If this line is dedented and the number of indent spaces is valid " (multiple of the indentation size), trust the user - let dedent_size = current - indent(a:lnum - 1) + let dedent_size = current - base if dedent_size < 0 && current % s:sw() == 0 return -1 endif diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index 1eea365..e300cb0 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -216,6 +216,14 @@ shared_examples_for "vim" do end end + describe "when current line is dedented compared to the last non-empty line" do + before { vim.feedkeys 'i\\if x:\y = True\\\' } + it "and current line has a valid indentation (Part 1)" do + vim.feedkeys '0i\if y:' + proposed_indent.should == -1 + end + end + describe "when an 'if' is followed by" do before { vim.feedkeys 'i\\if x:\' } it "an elif, it lines up with the 'if'" do