From: Ivan Smirnov Date: Mon, 21 Aug 2017 15:59:17 +0000 (+0100) Subject: Indent next line if prev line is empty (+tests) (#88) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/e0be8bfc4ff68e6eb26662fe3a1881cba225a44e?ds=sidebyside;hp=--cc Indent next line if prev line is empty (+tests) (#88) --- e0be8bfc4ff68e6eb26662fe3a1881cba225a44e diff --git a/indent/python.vim b/indent/python.vim index 19b649e..347e60d 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -301,6 +301,13 @@ function! s:indent_like_previous_line(lnum) let empty = getline(a:lnum) =~# '^\s*$' + " Current and prev line are empty, next is not -> indent like next. + if empty && a:lnum > 1 && + \ (getline(a:lnum - 1) =~# '^\s*$') && + \ !(getline(a:lnum + 1) =~# '^\s*$') + return indent(a:lnum + 1) + endif + " 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 diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index 85bc04b..23c1629 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -168,6 +168,20 @@ shared_examples_for "vim" do end end + describe "when an empty line is after empty line / before non-empty" do + it "is indented like the next line" do + vim.feedkeys 'idef a():\1\\\2\<1\\\\0i\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'