From: Hynek Schlawack Date: Sun, 6 Apr 2014 12:28:27 +0000 (+0200) Subject: Merge pull request #24 from has2k1/fix-indent-eagerness X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/358e8d6bd5911cea0f6b9c0be1db1b80d80a83cf?hp=9370cda99be0cfe529c40e5c6ce48ef01940a266 Merge pull request #24 from has2k1/fix-indent-eagerness Refix issue #5 (Correct indent after end of block) --- diff --git a/indent/python.vim b/indent/python.vim index d86eabb..461e962 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -179,6 +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(a:lnum) " Jump to last character in previous line. call cursor(lnum, len(text)) @@ -215,6 +216,13 @@ function! s:indent_like_previous_line(lnum) return -1 endif + " 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 - base + if dedent_size < 0 && current % s:sw() == 0 + return -1 + endif + " In all other cases, line up with the start of the previous statement. return base endfunction diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index cd79e36..15e265a 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -199,7 +199,7 @@ shared_examples_for "vim" do end describe "when current line is dedented compared to previous line" do - before { vim.feedkeys 'i\\if x:\return True\\' } + 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 @@ -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" 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