From b3a7395ce49b13145bbb54b1cdbfe6a33585bfe9 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 13 May 2019 22:48:12 +0200 Subject: [PATCH] Improve/fix indent with closing parenthesis (#129) Fixes https://github.com/Vimjas/vim-python-pep8-indent/issues/126 --- indent/python.vim | 7 ++++++- spec/indent/indent_spec.rb | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) 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 -- 2.39.2