X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/eed8e99ce344d773997c4683aef9de3e2ed7ec62..c4b633407dcd7e7b7b5c9a780edb3a8dc906eb7c:/indent/python.vim diff --git a/indent/python.vim b/indent/python.vim index 7b6580a..9b8e9b1 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -19,7 +19,8 @@ setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif,=except let s:maxoff = 50 let s:block_rules = { - \ '^\s*\(elif\|else\)\>': ['if', 'elif'], + \ '^\s*elif\>': ['if', 'elif'], + \ '^\s*else\>': ['if', 'elif', 'for', 'try', 'except'], \ '^\s*except\>': ['try', 'except'], \ '^\s*finally\>': ['try', 'except', 'else'] \ } @@ -80,7 +81,7 @@ function! s:find_opening_paren(...) call filter(positions, 'v:val[0]') call sort(positions, 's:pair_sort') - return get(positions, 0, [0, 0]) + return get(positions, -1, [0, 0]) endfunction " Find the start of a multi-line statement @@ -132,13 +133,22 @@ function! s:indent_like_opening_paren(lnum) if nothing_after_opening_paren if starts_with_closing_paren - return base + let res = base else - return base + s:sw() + let res = base + s:sw() endif else " Indent to match position of opening paren. - return paren_col + let res = paren_col + endif + + " If this line is the continuation of a control statement + " indent further to distinguish the continuation line + " from the next logical line. + if text =~# s:control_statement && res == base + s:sw() + return base + s:sw() * 2 + else + return res endif endfunction