Allow highlighting background between matches

This commit is contained in:
Andy K. Massimino
2018-11-09 11:18:00 -05:00
parent 1f70ad5445
commit c677d09abc
3 changed files with 57 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ function! s:init_options()
call s:init_option('matchup_matchparen_pumvisible', 1)
call s:init_option('matchup_matchparen_nomode', '')
call s:init_option('matchup_matchparen_hi_surround_always', 0)
call s:init_option('matchup_matchparen_hi_background', 0)
call s:init_option('matchup_matchparen_timeout',
\ get(g:, 'matchparen_timeout', 300))

View File

@@ -356,6 +356,11 @@ function! s:matchparen.highlight(...) abort dict " {{{1
" add highlighting matches
call s:add_matches(l:corrlist, l:current)
" highlight the background between parentheses
if g:matchup_matchparen_hi_background >= 1
call s:highlight_background(l:corrlist)
endif
call matchup#perf#toc('matchparen.highlight', 'end')
endfunction
@@ -421,6 +426,31 @@ function! s:highlight_surrounding(...) " {{{1
" add highlighting matches
call s:add_matches(l:corrlist)
" highlight the background between parentheses
if g:matchup_matchparen_hi_background >= 2
call s:highlight_background(l:corrlist)
endif
endfunction
" }}}1
function! s:highlight_background(corrlist) " {{{1
let [l:lo1, l:lo2] = [a:corrlist[0], a:corrlist[-1]]
let l:inclusive = 0
if l:inclusive
call s:add_background_matches(
\ l:lo1.lnum,
\ l:lo1.cnum,
\ l:lo2.lnum,
\ l:lo2.cnum + matchup#delim#end_offset(l:lo2))
else
call s:add_background_matches(
\ l:lo1.lnum,
\ l:lo1.cnum + matchup#delim#end_offset(l:lo1) + 1,
\ l:lo2.lnum,
\ l:lo2.cnum - 1)
endif
endfunction
"}}}1
@@ -551,6 +581,31 @@ function! s:add_matches(corrlist, ...) " {{{1
endfor
endfunction
" }}}1
function! s:add_background_matches(line1, col1, line2, col2) " {{{1
if a:line1 == a:line2 && a:col1 > a:col2
return
endif
let l:curline = a:line1
while l:curline <= a:line2
let l:endline = min([l:curline+7, a:line2])
let l:list = range(l:curline, l:endline)
if l:curline == a:line1
let l:list[0] = [a:line1, a:col1,
\ l:curline == a:line2 ? (a:col2-a:col1+1)
\ : strlen(getline(a:line1))]
endif
if l:endline == a:line2 && l:curline != a:line2
let l:list[-1] = [a:line2, 1, a:col2]
endif
call add(w:matchup_match_id_list,
\ matchaddpos('MatchBackground', l:list, -1))
let l:curline = l:endline+1
endwhile
endfunction
" }}}1
let &cpo = s:save_cpo

View File

@@ -45,6 +45,7 @@ command! DoMatchParen call matchup#matchparen#toggle(1)
hi def link MatchParenCur MatchParen
hi def link MatchWord MatchParen
" hi def link MatchWordCur MatchParenCur
hi def link MatchBackground ColorColumn
if get(g:, 'matchup_override_vimtex', 0)
let g:vimtex_matchparen_enabled = 0