let g:python_pep8_indent_hang_closing = 0
endif
+" TODO: check required patch for timeout argument, likely lower than 7.3.429 though.
+if !exists('g:python_pep8_indent_searchpair_timeout')
+ if has('patch-8.0.1483')
+ let g:python_pep8_indent_searchpair_timeout = 150
+ else
+ let g:python_pep8_indent_searchpair_timeout = 0
+ endif
+endif
+
let s:block_rules = {
\ '^\s*elif\>': ['if', 'elif'],
\ '^\s*except\>': ['try', 'except'],
" jedi* refers to syntax definitions from jedi-vim for call signatures, which
" are inserted temporarily into the buffer.
let s:skip_special_chars = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
- \ '=~? "\\vstring|comment|jedi\\S"'
+ \ '=~? "\\vstring|comment|^pythonbytes%(contents)=$|jedi\\S"'
let s:skip_after_opening_paren = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
\ '=~? "\\vcomment|jedi\\S"'
for [p, maxoff] in items(s:paren_pairs)
let stopline = max([0, line('.') - maxoff, nearest[0]])
let next = searchpairpos(
- \ '\V'.p[0], '', '\V'.p[1], 'bnW', s:skip_special_chars, stopline)
+ \ '\V'.p[0], '', '\V'.p[1], 'bnW', s:skip_special_chars, stopline, g:python_pep8_indent_searchpair_timeout)
if next[0] && (next[0] > nearest[0] || (next[0] == nearest[0] && next[1] > nearest[1]))
let nearest = next
endif
" Find possible indent(s) of the block starter that matches the current line.
function! s:find_start_of_block(lnum, types, multiple)
let r = []
- let types = copy(a:types)
let re = '\V\^\s\*\('.join(a:types, '\|').'\)\>'
let lnum = a:lnum
let last_indent = indent(lnum) + 1
while lnum > 0 && last_indent > 0
let indent = indent(lnum)
if indent < last_indent
- for type in types
- let re = '\v^\s*'.type.'>'
- if getline(lnum) =~# re
- if !a:multiple
- return [indent]
- endif
- if index(r, indent) == -1
- let r += [indent]
- endif
- " Remove any handled type, e.g. 'if'.
- call remove(types, index(types, type))
+ if getline(lnum) =~# re
+ if !a:multiple
+ return [indent]
+ endif
+ if index(r, indent) == -1
+ let r += [indent]
endif
- endfor
- let last_indent = indent(lnum)
+ let last_indent = indent
+ endif
endif
let lnum = prevnonblank(lnum - 1)
endwhile
" Is the syntax at lnum (and optionally cnum) a python string?
function! s:is_python_string(lnum, ...)
let line = getline(a:lnum)
- let linelen = len(line)
- if linelen < 1
- let linelen = 1
+ if a:0
+ let cols = type(a:1) != type([]) ? [a:1] : a:1
+ else
+ let cols = range(1, max([1, len(line)]))
endif
- let cols = a:0 ? type(a:1) != type([]) ? [a:1] : a:1 : range(1, linelen)
for cnum in cols
if match(map(synstack(a:lnum, cnum),
\ "synIDattr(v:val, 'name')"), 'python\S*String') == -1
let prevline = getline(a:lnum-1)
" Multilinestrings: continous, docstring or starting.
- if s:is_python_string(a:lnum-1, len(prevline))
+ if s:is_python_string(a:lnum-1, max([1, len(prevline)]))
\ && (s:is_python_string(a:lnum, 1)
\ || match(line, '^\%("""\|''''''\)') != -1)
if match_quotes != -1
" closing multiline string
let quotes = line[match_quotes:(match_quotes+2)]
- let pairpos = searchpairpos(quotes, '', quotes, 'b')
+ let pairpos = searchpairpos(quotes, '', quotes, 'b', 1, g:python_pep8_indent_searchpair_timeout)
if pairpos[0] != 0
return indent(pairpos[0])
else
endif
if s:is_python_string(a:lnum-1)
- " Previous line is (completely) a string.
- return indent(a:lnum-1)
+ " Previous line is (completely) a string: keep current indent.
+ return -1
endif
if match(prevline, '^\s*\%("""\|''''''\)') != -1