Skip to content

Redefine highlights on colorscheme changes #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions autoload/coverage.vim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ endif
if !exists('s:coverage_states')
let s:coverage_states = ['covered', 'uncovered', 'partial']
endif
let s:highlights_defined = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to guard this with if exists('s:highlights_defined')? autoload files can be re-executed whenever and AFAICT this shouldn't be reset to 0 in that case.


"}}}

Expand All @@ -46,17 +47,15 @@ endfunction
" Defines highlighting rules for coverage colors and defines text signs for each
" coverage state, as defined via plugin flags. See |coverage-config|.
function! s:DefineHighlighting() abort
if !hlexists('coverage_covered')
for l:state in s:coverage_states
execute 'highlight coverage_' . l:state .
for l:state in s:coverage_states
execute 'highlight coverage_' . l:state .
\ ' ctermbg=' . s:plugin.Flag(l:state . '_ctermbg') .
\ ' ctermfg=' . s:plugin.Flag(l:state . '_ctermfg') .
\ ' guibg=' . s:plugin.Flag(l:state . '_guibg') .
\ ' guifg=' . s:plugin.Flag(l:state . '_guifg')
execute 'sign define sign_' . l:state . ' text=' .
execute 'sign define sign_' . l:state . ' text=' .
\ s:plugin.Flag(l:state . '_text') . ' texthl=coverage_' . l:state
endfor
endif
endfor
endfunction


Expand All @@ -67,7 +66,9 @@ endfunction
" @default show_stats=1
function! s:RenderFromCache(filename, ...) abort
let l:show_stats = maktaba#ensure#IsBool(get(a:, 1, 1))
call s:DefineHighlighting()
if !s:highlights_defined
call s:DefineHighlighting()
endif
if (has_key(s:cache, a:filename))
let l:data = s:cache[a:filename]
for l:state in s:coverage_states
Expand Down Expand Up @@ -314,4 +315,12 @@ function! coverage#EnsureProvider(provider) abort
endif
endfunction


""
" Re-define highlights after the colorscheme was changed.
augroup coverage_highlights
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autocmds should be defined in a file plugin/autocmds.vim (w/ the standard maktaba#plugin#Enter guard) so they're loaded in a predictable manner and can be disabled if needed.

au!
autocmd ColorScheme * if s:highlights_defined | call s:DefineHighlighting() | endif
augroup END

"}}}