@@ -48,13 +48,13 @@ if !exists('g:python_pep8_indent_searchpair_timeout')
4848endif
4949
5050let s: block_rules = {
51- \ ' ^\s*elif\>' : [' if' , ' elif' ],
52- \ ' ^\s*except\>' : [' try' , ' except' ],
53- \ ' ^\s*finally\>' : [' try' , ' except' , ' else' ]
54- \ }
51+ \ ' ^\s*elif\>' : [[ ' if' , ' elif' ], [ ' else ' ] ],
52+ \ ' ^\s*except\>' : [[ ' try' , ' except' ], [] ],
53+ \ ' ^\s*finally\>' : [[ ' try' , ' except' , ' else' ], [] ]
54+ \ }
5555let s: block_rules_multiple = {
56- \ ' ^\s*else\>' : [' if' , ' elif' , ' for' , ' try' , ' except' ],
57- \ }
56+ \ ' ^\s*else\>' : [[ ' if' , ' elif' , ' for' , ' try' , ' except' ], []]
57+ \ }
5858" Pairs to look for when searching for opening parenthesis.
5959" The value is the maximum offset in lines.
6060let s: paren_pairs = {' ()' : 50 , ' []' : 100 , ' {}' : 1000 }
@@ -150,15 +150,23 @@ function! s:find_start_of_multiline_statement(lnum)
150150endfunction
151151
152152" Find possible indent(s) of the block starter that matches the current line.
153- function ! s: find_start_of_block (lnum, types, multiple)
153+ function ! s: find_start_of_block (lnum, types, skip , multiple) abort
154154 let r = []
155155 let re = ' \V\^\s\*\(' .join (a: types , ' \|' ).' \)\>'
156+ if ! empty (a: skip )
157+ let re_skip = ' \V\^\s\*\(' .join (a: skip , ' \|' ).' \)\>'
158+ else
159+ let re_skip = ' '
160+ endif
156161 let lnum = a: lnum
157162 let last_indent = indent (lnum) + 1
158163 while lnum > 0 && last_indent > 0
159164 let indent = indent (lnum)
160165 if indent < last_indent
161- if getline (lnum) = ~# re
166+ let line = getline (lnum)
167+ if ! empty (re_skip) && line = ~# re_skip
168+ let last_indent = indent
169+ elseif line = ~# re
162170 if ! a: multiple
163171 return [indent ]
164172 endif
@@ -239,14 +247,16 @@ function! s:indent_like_block(lnum)
239247 let text = getline (a: lnum )
240248 for [multiple, block_rules] in [
241249 \ [0 , s: block_rules ],
242- \ [1 , s: block_rules_multiple ]]
243- for [line_re, blocks] in items (block_rules)
250+ \ [1 , s: block_rules_multiple ],
251+ \ ]
252+ for [line_re, blocks_ignore] in items (block_rules)
244253 if text !~# line_re
245254 continue
246255 endif
247256
248- let indents = s: find_start_of_block (a: lnum - 1 , blocks, multiple)
249- if ! len (indents)
257+ let [blocks, skip ] = blocks_ignore
258+ let indents = s: find_start_of_block (a: lnum - 1 , blocks, skip , multiple)
259+ if empty (indents)
250260 return -1
251261 endif
252262 if len (indents) == 1
0 commit comments