Skip to content

Commit b3a7395

Browse files
authored
Improve/fix indent with closing parenthesis (#129)
Fixes #126
1 parent 784f6cc commit b3a7395

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

indent/python.vim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,12 @@ function! s:indent_like_opening_paren(lnum)
222222
if starts_with_closing_paren && !hang_closing
223223
let res = base
224224
else
225-
return base + s:sw()
225+
let res = base + s:sw()
226+
227+
" Special case for parenthesis.
228+
if text[paren_col-1] ==# '(' && getline(a:lnum) !~# '\v\)\s*:?\s*$'
229+
return res
230+
endif
226231
endif
227232
else
228233
" Indent to match position of opening paren.

spec/indent/indent_spec.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,24 @@
203203
end
204204

205205
describe "when using a function definition" do
206-
it "indents shiftwidth spaces" do
206+
it "handles indent with closing parenthesis on same line" do
207207
vim.feedkeys 'idef long_function_name(\<CR>arg'
208208
indent.should == shiftwidth
209+
vim.feedkeys '):'
210+
indent.should == shiftwidth * 2
211+
end
212+
213+
it "handles indent with closing parenthesis on new line" do
214+
vim.feedkeys 'idef long_function_name(\<CR>arg'
215+
indent.should == shiftwidth
216+
vim.feedkeys '\<CR>'
217+
indent.should == shiftwidth
218+
vim.feedkeys ')'
219+
indent.should == (hang_closing ? shiftwidth * 2 : 0)
220+
vim.feedkeys ':'
221+
indent.should == (hang_closing ? shiftwidth * 2 : 0)
222+
vim.feedkeys '\<Esc>k'
223+
indent.should == shiftwidth
209224
end
210225
end
211226

0 commit comments

Comments
 (0)