Skip to content

Commit

Permalink
Allow highlighting background between matches
Browse files Browse the repository at this point in the history
  • Loading branch information
andymass committed Nov 9, 2018
1 parent 1f70ad5 commit c677d09
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions autoload/matchup.vim
Expand Up @@ -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))
Expand Down
55 changes: 55 additions & 0 deletions autoload/matchup/matchparen.vim
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions plugin/matchup.vim
Expand Up @@ -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
Expand Down

0 comments on commit c677d09

Please sign in to comment.