Skip to content

Commit 1bc09cb

Browse files
committed
Intermediate fix for indenting huge dicts
This uses different offsets for the type of pairs: '()' and '[]' will only look for just 20 lines above, while 1000 lines are used for '{}', which might be a huge dict. Ref: #64.
1 parent e0be8bf commit 1bc09cb

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

indent/python.vim

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ if !exists('g:python_pep8_indent_multiline_string')
3434
let g:python_pep8_indent_multiline_string = 0
3535
endif
3636

37-
let s:maxoff = 50
3837
let s:block_rules = {
3938
\ '^\s*elif\>': ['if', 'elif'],
4039
\ '^\s*except\>': ['try', 'except'],
@@ -43,7 +42,9 @@ let s:block_rules = {
4342
let s:block_rules_multiple = {
4443
\ '^\s*else\>': ['if', 'elif', 'for', 'try', 'except'],
4544
\ }
46-
let s:paren_pairs = ['()', '{}', '[]']
45+
" Pairs to look for when searching for opening parenthesis.
46+
" The value is the maximum offset in lines.
47+
let s:paren_pairs = {'()': 10, '[]': 100, '{}': 1000}
4748
if &filetype ==# 'pyrex' || &filetype ==# 'cython'
4849
let b:control_statement = '\v^\s*(class|def|if|while|with|for|except|cdef|cpdef)>'
4950
else
@@ -105,13 +106,12 @@ function! s:find_opening_paren(...)
105106
return ret
106107
endif
107108

108-
let stopline = max([0, line('.') - s:maxoff])
109-
110109
" Return if cursor is in a comment.
111110
exe 'if' s:skip_search '| return [0, 0] | endif'
112111

113112
let positions = []
114-
for p in s:paren_pairs
113+
for [p, maxoff] in items(s:paren_pairs)
114+
let stopline = max([0, line('.') - maxoff])
115115
call add(positions, searchpairpos(
116116
\ '\V'.p[0], '', '\V'.p[1], 'bnW', s:skip_special_chars, stopline))
117117
endfor

0 commit comments

Comments
 (0)