|
66 | 66 | endif |
67 | 67 | let s:stop_statement = '^\s*\(break\|continue\|raise\|return\|pass\)\>' |
68 | 68 |
|
69 | | -" Skip strings and comments. Return 1 for chars to skip. |
70 | | -" jedi* refers to syntax definitions from jedi-vim for call signatures, which |
71 | | -" are inserted temporarily into the buffer. |
72 | | -" let s:skip_special_chars = '(execute("sleep 100m") && 0) || synIDattr(synID(line("."), col("."), 0), "name") ' . |
73 | | -function! s:_skip_special_chars() |
74 | | - return synIDattr(synID(line('.'), col('.'), 0), 'name') |
75 | | - \ =~? "\\vstring|comment|^pythonbytes%(contents)=$|jedi\\S" |
76 | | -endfunction |
77 | | -let s:skip_special_chars = 's:_skip_special_chars()' |
78 | | - |
79 | 69 | let s:skip_after_opening_paren = 'synIDattr(synID(line("."), col("."), 0), "name") ' . |
80 | 70 | \ '=~? "\\vcomment|jedi\\S"' |
81 | 71 |
|
82 | | -" Also ignore anything concealed. |
83 | | -" TODO: doc; likely only necessary with jedi-vim, where a better version is |
84 | | -" planned (https://github.com/Vimjas/vim-python-pep8-indent/pull/98). |
85 | | -if get(g:, 'python_pep8_indent_skip_concealed', 0) |
| 72 | +if !get(g:, 'python_pep8_indent_skip_concealed', 0) || !has('conceal') |
| 73 | + " Skip strings and comments. Return 1 for chars to skip. |
| 74 | + " jedi* refers to syntax definitions from jedi-vim for call signatures, which |
| 75 | + " are inserted temporarily into the buffer. |
| 76 | + function! s:_skip_special_chars(line, col) |
| 77 | + return synIDattr(synID(a:line, a:col, 0), 'name') |
| 78 | + \ =~? "\\vstring|comment|^pythonbytes%(contents)=$|jedi\\S" |
| 79 | + endfunction |
| 80 | +else |
| 81 | + " Also ignore anything concealed. |
| 82 | + " TODO: doc; likely only necessary with jedi-vim, where a better version is |
| 83 | + " planned (https://github.com/Vimjas/vim-python-pep8-indent/pull/98). |
| 84 | + |
86 | 85 | " Wrapper around synconcealed for older Vim (7.3.429, used on Travis CI). |
87 | 86 | function! s:is_concealed(line, col) |
88 | 87 | let concealed = synconcealed(a:line, a:col) |
89 | 88 | return len(concealed) && concealed[0] |
90 | 89 | endfunction |
91 | | - if has('conceal') |
92 | | - let s:skip_special_chars .= '|| s:is_concealed(line("."), col("."))' |
93 | | - endif |
| 90 | + |
| 91 | + function! s:_skip_special_chars(line, col) |
| 92 | + return synIDattr(synID(a:line, a:col, 0), 'name') |
| 93 | + \ =~? "\\vstring|comment|^pythonbytes%(contents)=$|jedi\\S" |
| 94 | + \ || s:is_concealed(a:line, a:col) |
| 95 | + endfunction |
94 | 96 | endif |
95 | 97 |
|
96 | 98 |
|
@@ -125,8 +127,19 @@ function! s:find_opening_paren(...) |
125 | 127 | let nearest = [0, 0] |
126 | 128 | for [p, maxoff] in items(s:paren_pairs) |
127 | 129 | let stopline = max([0, line('.') - maxoff, nearest[0]]) |
128 | | - let next = searchpairpos( |
129 | | - \ '\V'.p[0], '', '\V'.p[1], 'bnW', s:skip_special_chars, stopline, g:python_pep8_indent_searchpair_timeout) |
| 130 | + let found = 0 |
| 131 | + while 1 |
| 132 | + let next = searchpairpos( |
| 133 | + \ '\V'.p[0], '', '\V'.p[1], 'bnW', '', stopline, g:python_pep8_indent_searchpair_timeout) |
| 134 | + |
| 135 | + if !next[0] |
| 136 | + break |
| 137 | + endif |
| 138 | + if !s:_skip_special_chars(next[0], next[1]) |
| 139 | + break |
| 140 | + endif |
| 141 | + call cursor(next[0], next[1]) |
| 142 | + endwhile |
130 | 143 | if next[0] && (next[0] > nearest[0] || (next[0] == nearest[0] && next[1] > nearest[1])) |
131 | 144 | let nearest = next |
132 | 145 | endif |
@@ -281,24 +294,23 @@ function! s:indent_like_previous_line(lnum) |
281 | 294 | let base = indent(start) |
282 | 295 | let current = indent(a:lnum) |
283 | 296 |
|
284 | | - " Jump to last character in previous line. |
285 | | - call cursor(lnum, len(text)) |
286 | | - let ignore_last_char = eval(s:skip_special_chars) |
| 297 | + " Ignore last character in previous line? |
| 298 | + let lastcol = len(text) |
| 299 | + let col = lastcol |
287 | 300 |
|
288 | 301 | " Search for final colon that is not inside something to be ignored. |
289 | 302 | while 1 |
290 | | - let curpos = getpos('.')[2] |
291 | | - if curpos == 1 | break | endif |
292 | | - if text[curpos-1] =~# '\s' || eval(s:skip_special_chars) |
293 | | - normal! h |
| 303 | + if col == 1 | break | endif |
| 304 | + if text[col-1] =~# '\s' || s:_skip_special_chars(lnum, col) |
| 305 | + let col = col - 1 |
294 | 306 | continue |
295 | | - elseif text[curpos-1] ==# ':' |
| 307 | + elseif text[col-1] ==# ':' |
296 | 308 | return base + s:sw() |
297 | 309 | endif |
298 | 310 | break |
299 | 311 | endwhile |
300 | 312 |
|
301 | | - if text =~# '\\$' && !ignore_last_char |
| 313 | + if text =~# '\\$' && !s:_skip_special_chars(lnum, lastcol) |
302 | 314 | " If this line is the continuation of a control statement |
303 | 315 | " indent further to distinguish the continuation line |
304 | 316 | " from the next logical line. |
|
0 commit comments