Skip to content

Commit 30014e2

Browse files
committed
Improve indent for with statement
1 parent 925b3e2 commit 30014e2

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

indent/python.vim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ function! GetPEP8PythonIndent() abort
137137
elseif getline(v:lnum - 1) =~# s:lcont
138138
" line continuation
139139
if s:is_compound_stmt(ll)
140-
let ind += s:ml_stmt() ? shiftwidth() * 2 : shiftwidth()
140+
if ll =~# '\v^\s*<with>'
141+
let ind += len('with') + 1
142+
else
143+
let ind += s:ml_stmt() ? shiftwidth() * 2 : shiftwidth()
144+
endif
141145
else
142146
let ind += s:cont()
143147
endif

test/indent.vimspec

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,15 @@ Describe filetype indent
492492
Assert Equals(Insert(in), Buffer(out))
493493
End
494494

495+
It indents the with statement (line continuation)
496+
let in = "with open('a') as fp1, \\\<CR>open('b') as fp2:"
497+
let out = [
498+
\ 'with open(''a'') as fp1, \',
499+
\ ' open(''b'') as fp2:',
500+
\]
501+
Assert Equals(Insert(in), Buffer(out))
502+
End
503+
495504
It indents compound statements (line continuation)
496505
let in = "def func():\<CR>"
497506
let in .= "\\\<CR>0\<C-D>if 1:\<CR>pass\<CR>"

0 commit comments

Comments
 (0)