X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/7665325e833a60a9217f7e62c37069ef6b359d18..0586a518f9cc8a590a35fd2443be4c0677bc45ad:/indent/python.vim diff --git a/indent/python.vim b/indent/python.vim index c56c2dc..e3c2352 100644 --- a/indent/python.vim +++ b/indent/python.vim @@ -38,6 +38,15 @@ if !exists('g:python_pep8_indent_hang_closing') 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'], @@ -60,20 +69,28 @@ let s:stop_statement = '^\s*\(break\|continue\|raise\|return\|pass\)\>' " Skip strings and comments. Return 1 for chars to skip. " 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"' +" let s:skip_special_chars = '(execute("sleep 100m") && 0) || synIDattr(synID(line("."), col("."), 0), "name") ' . +function! s:_skip_special_chars() + return synIDattr(synID(line('.'), col('.'), 0), 'name') + \ =~? "\\vstring|comment|^pythonbytes%(contents)=$|jedi\\S" +endfunction +let s:skip_special_chars = 's:_skip_special_chars()' let s:skip_after_opening_paren = 'synIDattr(synID(line("."), col("."), 0), "name") ' . \ '=~? "\\vcomment|jedi\\S"' " Also ignore anything concealed. -" Wrapper around synconcealed for older Vim (7.3.429, used on Travis CI). -function! s:is_concealed(line, col) - let concealed = synconcealed(a:line, a:col) - return len(concealed) && concealed[0] -endfunction -if has('conceal') - let s:skip_special_chars .= '|| s:is_concealed(line("."), col("."))' +" TODO: doc; likely only necessary with jedi-vim, where a better version is +" planned (https://github.com/Vimjas/vim-python-pep8-indent/pull/98). +if get(g:, 'python_pep8_indent_skip_concealed', 0) + " Wrapper around synconcealed for older Vim (7.3.429, used on Travis CI). + function! s:is_concealed(line, col) + let concealed = synconcealed(a:line, a:col) + return len(concealed) && concealed[0] + endfunction + if has('conceal') + let s:skip_special_chars .= '|| s:is_concealed(line("."), col("."))' + endif endif @@ -110,7 +127,7 @@ function! s:find_opening_paren(...) 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 @@ -364,7 +381,7 @@ function! GetPythonPEPIndent(lnum) 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