From 222fbda19d59ba0124aedade5a3ee4a10fb90a93 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Sat, 29 Jul 2017 14:09:18 +0100 Subject: [PATCH] Indent empty lines inside blocks (#81) --- indent/python.vim | 6 ++++-- spec/indent/indent_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) 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' -- 2.39.2