Fix #493: Improved highlight matching delims

This commit is contained in:
Karl Yngve Lervåg 2016-07-18 22:15:43 +02:00
parent 8dd4ed77db
commit a80a2600b0
2 changed files with 20 additions and 37 deletions

View File

@ -408,6 +408,8 @@ function! vimtex#delim#get_matching(delim) " {{{1
let l:matching.corr = a:delim.match let l:matching.corr = a:delim.match
let l:matching.side = a:delim.is_open ? 'close' : 'open' let l:matching.side = a:delim.is_open ? 'close' : 'open'
let l:matching.is_open = !a:delim.is_open let l:matching.is_open = !a:delim.is_open
let l:matching.re.corr = a:delim.re.this
let l:matching.re.this = a:delim.re.corr
if l:matching.type ==# 'delim' if l:matching.type ==# 'delim'
let l:matching.corr_delim = a:delim.delim let l:matching.corr_delim = a:delim.delim

View File

@ -183,49 +183,30 @@ endfunction
" }}}1 " }}}1
function! s:highlight_matching_pair() " {{{1 function! s:highlight_matching_pair() " {{{1
if exists('*matchaddpos') if exists('s:match_id1')
call s:highlight_matching_pair_new() call matchdelete(s:match_id1)
else call matchdelete(s:match_id2)
call s:highlight_matching_pair_old() unlet s:match_id1
endif unlet s:match_id2
endfunction
" }}}1
function! s:highlight_matching_pair_new() " {{{1
if exists('s:match_id')
call matchdelete(s:match_id)
unlet s:match_id
endif endif
if vimtex#util#in_comment() | return | endif if vimtex#util#in_comment() | return | endif
let l:d1 = vimtex#delim#get_current('all', 'both') let l:current = vimtex#delim#get_current('all', 'both')
if empty(l:d1) | return | endif if empty(l:current) | return | endif
let l:d2 = vimtex#delim#get_matching(l:d1) let l:corresponding = vimtex#delim#get_matching(l:current)
if empty(l:d2) | return | endif if empty(l:corresponding) | return | endif
let s:match_id = matchaddpos('MatchParen', let [l:o, l:c] = l:current.is_open
\ [[l:d1.lnum, l:d1.cnum, strlen(l:d1.match)], \ ? [l:current, l:corresponding]
\ [l:d2.lnum, l:d2.cnum, strlen(l:d2.match)]]) \ : [l:corresponding, l:current]
endfunction
" }}}1 let s:match_id1 = matchadd('MatchParen',
function! s:highlight_matching_pair_old() " {{{1 \ '\%' . l:o.lnum . 'l\%' . l:o.cnum . 'c' . l:o.re.this . '\ze\_.*'
2match none \ . '\%' . l:c.lnum . 'l\%' . l:c.cnum . 'c' . l:c.re.this)
if vimtex#util#in_comment() | return | endif let s:match_id2 = matchadd('MatchParen',
\ '\%' . l:o.lnum . 'l\%' . l:o.cnum . 'c' . l:o.re.this . '\_.*\zs'
let l:d1 = vimtex#delim#get_current('all', 'both') \ . '\%' . l:c.lnum . 'l\%' . l:c.cnum . 'c' . l:c.re.this)
if empty(l:d1) | return | endif
let l:d2 = vimtex#delim#get_matching(l:d1)
if empty(l:d2) | return | endif
let [l1, c1, l2, c2] = l:d1.side ==# 'open'
\ ? [l:d1.lnum, l:d1.cnum, l:d2.lnum, l:d2.cnum]
\ : [l:d2.lnum, l:d2.cnum, l:d1.lnum, l:d1.cnum]
execute '2match MatchParen /'
\ . '\%' . l1 . 'l\%' . c1 . 'c' . l:d1.re.open
\ . '\|\%' . l2 . 'l\%' . c2 . 'c' . l:d1.re.close . '/'
endfunction endfunction
" }}}1 " }}}1