Skip to content

Commit 5a4cf72

Browse files
committed
s:find_opening_paren: pass lnum/col always, no winsaveview
1 parent d55fef9 commit 5a4cf72

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

indent/python.vim

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,14 @@ else
109109
endif
110110

111111
" Find backwards the closest open parenthesis/bracket/brace.
112-
function! s:find_opening_paren(...)
113-
" optional arguments: line and column (defaults to 1) to search around
114-
if a:0 > 0
115-
let view = winsaveview()
116-
call cursor(a:1, a:0 > 1 ? a:2 : 1)
117-
let ret = s:find_opening_paren()
118-
call winrestview(view)
119-
return ret
120-
endif
121-
112+
function! s:find_opening_paren(lnum, col)
122113
" Return if cursor is in a comment.
123-
if synIDattr(synID(line('.'), col('.'), 0), 'name') =~? 'comment'
114+
if synIDattr(synID(a:lnum, a:col, 0), 'name') =~? 'comment'
124115
return [0, 0]
125116
endif
126117

118+
call cursor(a:lnum, a:col)
119+
127120
let nearest = [0, 0]
128121
for [p, maxoff] in items(s:paren_pairs)
129122
let stopline = max([0, line('.') - maxoff, nearest[0]])
@@ -154,7 +147,7 @@ function! s:find_start_of_multiline_statement(lnum)
154147
if getline(lnum - 1) =~# '\\$'
155148
let lnum = prevnonblank(lnum - 1)
156149
else
157-
let [paren_lnum, _] = s:find_opening_paren(lnum)
150+
let [paren_lnum, _] = s:find_opening_paren(lnum, 1)
158151
if paren_lnum < 1
159152
return lnum
160153
else
@@ -211,7 +204,7 @@ endfunction
211204

212205
" Line up with open parenthesis/bracket/brace.
213206
function! s:indent_like_opening_paren(lnum)
214-
let [paren_lnum, paren_col] = s:find_opening_paren(a:lnum)
207+
let [paren_lnum, paren_col] = s:find_opening_paren(a:lnum, 1)
215208
if paren_lnum <= 0
216209
return -2
217210
endif
@@ -241,7 +234,7 @@ function! s:indent_like_opening_paren(lnum)
241234
" from the next logical line.
242235
if text =~# b:control_statement && res == base + s:sw()
243236
" But only if not inside parens itself (Flake's E127).
244-
let [paren_lnum, _] = s:find_opening_paren(paren_lnum)
237+
let [paren_lnum, _] = s:find_opening_paren(paren_lnum, 1)
245238
if paren_lnum <= 0
246239
return res + s:sw()
247240
endif

0 commit comments

Comments
 (0)