Do not jump over next delimiter when unbalanced pairs. Close #229.

This commit is contained in:
Israel Chauca Fuentes
2017-02-14 14:46:43 -05:00
parent 37122299b7
commit c97a824ed4
2 changed files with 25 additions and 7 deletions
+24 -6
View File
@@ -77,16 +77,30 @@ function! s:balance_pairs(pair, info, opts) "{{{1
let ahead = substitute(ahead, pat, '', 'g') let ahead = substitute(ahead, pat, '', 'g')
let lefts = 0 let lefts = 0
let rights = 0 let rights = 0
for c in split(behind, '\zs') for char in split(behind, '\zs')
if c ==# left if char ==# left
let lefts += 1 let lefts += 1
elseif c ==# right elseif char ==# right
let rights += rights < lefts let rights += rights < lefts
endif endif
endfor endfor
let lefts += count(split(ahead, '\zs'), left) let balance1 = lefts - rights
let rights += count(split(ahead, '\zs'), right) let lefts = 0
return lefts - rights let rights = 0
let balance2 = 0
for char in split(ahead, '\zs')
if char ==# left
let lefts += 1
elseif char ==# right
let rights += 1
endif
if lefts < rights
let balance2 -= 1
let lefts = 0
let rights = 0
endif
endfor
return balance1 + balance2
endfunction endfunction
function! s:info.template.is_escaped(...) "{{{1 function! s:info.template.is_escaped(...) "{{{1
@@ -347,6 +361,10 @@ function! s:keys4left(char, pair, info, opts) "{{{1
endfunction endfunction
function! s:keys4right(char, pair, info, opts) "{{{1 function! s:keys4right(char, pair, info, opts) "{{{1
if a:opts.balance_pairs && s:balance_pairs(a:pair, a:info, a:opts) > 0
3DMDebug "A1"
return ''
endif
if a:opts.jump_expansion if a:opts.jump_expansion
3DMDebug "40" 3DMDebug "40"
let around = matchstr(a:info.cur.prev_line, "\\S$") . matchstr(a:info.cur.next_line, "^\\s*\zs\\S") let around = matchstr(a:info.cur.prev_line, "\\S$") . matchstr(a:info.cur.next_line, "^\\s*\zs\\S")
+1 -1
View File
@@ -92,7 +92,7 @@ call DMTest_single('{()}', 'la\<magic>x', '{()}x', 0, 1)
let g:delimitMate_balance_pairs = 1 let g:delimitMate_balance_pairs = 1
call DMTest_pairs('ab cd)', "la(x", 'ab(x cd)') call DMTest_pairs('ab cd)', "la(x", 'ab(x cd)')
" Issue #229 " Issue #229
call DMTest_single('((ab cd)', "A)", '((abx cd))', 0, 1) call DMTest_pairs('((ab cd)', "A)", '((ab cd))')
unlet g:delimitMate_balance_pairs unlet g:delimitMate_balance_pairs
" Issue #220 " Issue #220