From: Ivan Smirnov Date: Sat, 29 Jul 2017 13:09:18 +0000 (+0100) Subject: Indent empty lines inside blocks (#81) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/222fbda19d59ba0124aedade5a3ee4a10fb90a93?ds=inline;hp=-c Indent empty lines inside blocks (#81) --- 222fbda19d59ba0124aedade5a3ee4a10fb90a93 diff --git a/indent/python.vim b/indent/python.vim index 8a479f4..b3a5141 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -303,17 +303,19 @@ function! s:indent_like_previous_line(lnum) return base + s:sw() endif + let empty = getline(a:lnum) =~# '^\s*$' + " If the previous statement was a stop-execution statement or a pass if getline(start) =~# s:stop_statement " Remove one level of indentation if the user hasn't already dedented - if indent(a:lnum) > base - s:sw() + if empty || current > base - s:sw() return base - s:sw() endif " Otherwise, trust the user return -1 endif - if s:is_dedented_already(current, base) + if !empty && s:is_dedented_already(current, base) return -1 endif diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index 342b301..0bd57b2 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -161,6 +161,27 @@ shared_examples_for "vim" do end end + describe "when line is empty inside a block" do + it "is indented like the previous line" do + vim.feedkeys 'idef a():\1\\2\kcc' + indent.should == shiftwidth + end + end + + describe "when line is empty inside a block following multi-line statement" do + it "is indented like the previous line" do + vim.feedkeys 'idef a():\x = (1 +\2)\\y\kcc' + indent.should == shiftwidth + end + end + + describe "when line is empty inside a block following stop statement" do + it "is indented like the previous line minus shiftwidth" do + vim.feedkeys 'iif x:\if y:\pass\\z\kcc' + indent.should == shiftwidth + end + end + describe "when using simple control structures" do it "indents shiftwidth spaces" do vim.feedkeys 'iwhile True:\pass'