diff --git a/autoload/vimtex/delim.vim b/autoload/vimtex/delim.vim index c718ac5..a4104fe 100644 --- a/autoload/vimtex/delim.vim +++ b/autoload/vimtex/delim.vim @@ -408,6 +408,8 @@ function! vimtex#delim#get_matching(delim) " {{{1 let l:matching.corr = a:delim.match let l:matching.side = a:delim.is_open ? 'close' : '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' let l:matching.corr_delim = a:delim.delim diff --git a/autoload/vimtex/motion.vim b/autoload/vimtex/motion.vim index 1800571..97254cd 100644 --- a/autoload/vimtex/motion.vim +++ b/autoload/vimtex/motion.vim @@ -183,49 +183,30 @@ endfunction " }}}1 function! s:highlight_matching_pair() " {{{1 - if exists('*matchaddpos') - call s:highlight_matching_pair_new() - else - call s:highlight_matching_pair_old() - endif -endfunction - -" }}}1 -function! s:highlight_matching_pair_new() " {{{1 - if exists('s:match_id') - call matchdelete(s:match_id) - unlet s:match_id + if exists('s:match_id1') + call matchdelete(s:match_id1) + call matchdelete(s:match_id2) + unlet s:match_id1 + unlet s:match_id2 endif if vimtex#util#in_comment() | return | endif - let l:d1 = vimtex#delim#get_current('all', 'both') - if empty(l:d1) | return | endif + let l:current = vimtex#delim#get_current('all', 'both') + if empty(l:current) | return | endif - let l:d2 = vimtex#delim#get_matching(l:d1) - if empty(l:d2) | return | endif + let l:corresponding = vimtex#delim#get_matching(l:current) + if empty(l:corresponding) | return | endif - let s:match_id = matchaddpos('MatchParen', - \ [[l:d1.lnum, l:d1.cnum, strlen(l:d1.match)], - \ [l:d2.lnum, l:d2.cnum, strlen(l:d2.match)]]) -endfunction + let [l:o, l:c] = l:current.is_open + \ ? [l:current, l:corresponding] + \ : [l:corresponding, l:current] -" }}}1 -function! s:highlight_matching_pair_old() " {{{1 - 2match none - if vimtex#util#in_comment() | return | endif - - let l:d1 = vimtex#delim#get_current('all', 'both') - 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 . '/' + let s:match_id1 = matchadd('MatchParen', + \ '\%' . l:o.lnum . 'l\%' . l:o.cnum . 'c' . l:o.re.this . '\ze\_.*' + \ . '\%' . l:c.lnum . 'l\%' . l:c.cnum . 'c' . l:c.re.this) + let s:match_id2 = matchadd('MatchParen', + \ '\%' . l:o.lnum . 'l\%' . l:o.cnum . 'c' . l:o.re.this . '\_.*\zs' + \ . '\%' . l:c.lnum . 'l\%' . l:c.cnum . 'c' . l:c.re.this) endfunction " }}}1