Skip to content

Commit e54a25c

Browse files
committed
s:find_opening_paren: use known nearest for stopline
1 parent 1bc09cb commit e54a25c

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

indent/python.vim

+8-10
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,16 @@ function! s:find_opening_paren(...)
109109
" Return if cursor is in a comment.
110110
exe 'if' s:skip_search '| return [0, 0] | endif'
111111

112-
let positions = []
112+
let nearest = [0, 0]
113113
for [p, maxoff] in items(s:paren_pairs)
114-
let stopline = max([0, line('.') - maxoff])
115-
call add(positions, searchpairpos(
116-
\ '\V'.p[0], '', '\V'.p[1], 'bnW', s:skip_special_chars, stopline))
114+
let stopline = max([0, line('.') - maxoff, nearest[0]])
115+
let next = searchpairpos(
116+
\ '\V'.p[0], '', '\V'.p[1], 'bnW', s:skip_special_chars, stopline)
117+
if next[0] && (next[0] > nearest[0] || (next[0] == nearest[0] && next[1] > nearest[1]))
118+
let nearest = next
119+
endif
117120
endfor
118-
119-
" Remove empty matches and return the type with the closest match
120-
call filter(positions, 'v:val[0]')
121-
call sort(positions, 's:pair_sort')
122-
123-
return get(positions, -1, [0, 0])
121+
return nearest
124122
endfunction
125123

126124
" Find the start of a multi-line statement

0 commit comments

Comments
 (0)