From: Daniel Hahler Date: Mon, 13 May 2019 20:48:12 +0000 (+0200) Subject: Improve/fix indent with closing parenthesis (#129) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/b3a7395ce49b13145bbb54b1cdbfe6a33585bfe9?hp=-c Improve/fix indent with closing parenthesis (#129) Fixes https://github.com/Vimjas/vim-python-pep8-indent/issues/126 --- b3a7395ce49b13145bbb54b1cdbfe6a33585bfe9 diff --git a/indent/python.vim b/indent/python.vim index 3c86195..aca216e 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -222,7 +222,12 @@ function! s:indent_like_opening_paren(lnum) if starts_with_closing_paren && !hang_closing let res = base else - return base + s:sw() + let res = base + s:sw() + + " Special case for parenthesis. + if text[paren_col-1] ==# '(' && getline(a:lnum) !~# '\v\)\s*:?\s*$' + return res + endif endif else " Indent to match position of opening paren. diff --git a/spec/indent/indent_spec.rb b/spec/indent/indent_spec.rb index 2ff0caf..55e2fba 100644 --- a/spec/indent/indent_spec.rb +++ b/spec/indent/indent_spec.rb @@ -203,9 +203,24 @@ shared_examples_for "vim" do end describe "when using a function definition" do - it "indents shiftwidth spaces" do + it "handles indent with closing parenthesis on same line" do vim.feedkeys 'idef long_function_name(\arg' indent.should == shiftwidth + vim.feedkeys '):' + indent.should == shiftwidth * 2 + end + + it "handles indent with closing parenthesis on new line" do + vim.feedkeys 'idef long_function_name(\arg' + indent.should == shiftwidth + vim.feedkeys '\' + indent.should == shiftwidth + vim.feedkeys ')' + indent.should == (hang_closing ? shiftwidth * 2 : 0) + vim.feedkeys ':' + indent.should == (hang_closing ? shiftwidth * 2 : 0) + vim.feedkeys '\k' + indent.should == shiftwidth end end