Reset default highlighting after loading a color scheme

Color schemes use `hi clear`, which clears the EasyMotion syntax
highlighting when a new color scheme is loaded. This change introduces
`autocmd`s which reset the default colors after loading a new color
scheme.

Closes #6.
This commit is contained in:
Kim Silkebækken 2011-03-31 13:29:07 +02:00
parent c48db22d4c
commit a7b7becea4

View File

@ -16,15 +16,13 @@
exec 'let g:EasyMotion_' . a:option . ' = ' . string(a:default)
endif
endfunction " }}}
function! s:InitHL(group, gui, cterm256, cterm) " {{{
if ! hlexists(a:group)
let guihl = printf('guibg=%s guifg=#%s gui=%s', a:gui[0], a:gui[1], a:gui[2])
let ctermhl = &t_Co == 256
\ ? printf('ctermbg=%s ctermfg=%s cterm=%s', a:cterm256[0], a:cterm256[1], a:cterm256[2])
\ : printf('ctermbg=%s ctermfg=%s cterm=%s', a:cterm[0], a:cterm[1], a:cterm[2])
function! s:InitHL(group, colors) " {{{
let guihl = printf('guibg=%s guifg=#%s gui=%s', a:colors.gui[0], a:colors.gui[1], a:colors.gui[2])
let ctermhl = &t_Co == 256
\ ? printf('ctermbg=%s ctermfg=%s cterm=%s', a:colors.cterm256[0], a:colors.cterm256[1], a:colors.cterm256[2])
\ : printf('ctermbg=%s ctermfg=%s cterm=%s', a:colors.cterm[0], a:colors.cterm[1], a:colors.cterm[2])
execute printf('hi %s %s %s', a:group, guihl, ctermhl)
endif
execute printf('hi default %s %s %s', a:group, guihl, ctermhl)
endfunction " }}}
call s:InitOption('keys', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
@ -33,8 +31,31 @@
call s:InitOption('do_shade', 1)
call s:InitOption('do_mapping', 1)
call s:InitHL(g:EasyMotion_target_hl, ['NONE', 'ff0000', 'bold'], ['NONE', '196', 'bold'], ['NONE', 'red', 'bold'])
call s:InitHL(g:EasyMotion_shade_hl, ['NONE', '585858', 'NONE'], ['NONE', '240', 'NONE'], ['NONE', 'darkgrey', 'NONE'])
" Init highlighting {{{
let s:target_hl_defaults = {
\ 'gui' : ['NONE', 'ff0000' , 'bold']
\ , 'cterm256': ['NONE', '196' , 'bold']
\ , 'cterm' : ['NONE', 'red' , 'bold']
\ }
let s:shade_hl_defaults = {
\ 'gui' : ['NONE', '585858' , 'NONE']
\ , 'cterm256': ['NONE', '240' , 'NONE']
\ , 'cterm' : ['NONE', 'darkgrey', 'NONE']
\ }
call s:InitHL(g:EasyMotion_target_hl, s:target_hl_defaults)
call s:InitHL(g:EasyMotion_shade_hl, s:shade_hl_defaults)
" Reset highlighting after loading a new color scheme {{{
augroup EasyMotionInitHL
autocmd!
autocmd ColorScheme * call s:InitHL(g:EasyMotion_target_hl, s:target_hl_defaults)
autocmd ColorScheme * call s:InitHL(g:EasyMotion_shade_hl, s:shade_hl_defaults)
augroup end
" }}}
" }}}
" }}}
" Default key mapping {{{
if g:EasyMotion_do_mapping