From c18a741f93a70bb16f63f1af199f6fb703436cb3 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Sat, 6 Jul 2013 00:29:41 +0000 Subject: [PATCH] refactor colorschemes to overwrite a base instead of replacing --- autoload/airline/themes/simple.vim | 6 ++-- plugin/airline.vim | 49 ++++++++++++++++-------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/autoload/airline/themes/simple.vim b/autoload/airline/themes/simple.vim index bb11efc..3013de8 100644 --- a/autoload/airline/themes/simple.vim +++ b/autoload/airline/themes/simple.vim @@ -19,9 +19,9 @@ let g:airline#themes#simple#normal = { \ 'file': [ '#ff0000' , '#080808' , 160 , s:bg , '' ] , \ 'inactive': [ '#4e4e4e' , '#080808' , 239 , s:bg , '' ] , \ } -let g:airline#themes#simple#normal_modified = copy(g:airline#themes#simple#normal) -let g:airline#themes#simple#normal_modified.info_separator = [ '#080808' , '#080808' , s:bg , s:bg , '' ] -let g:airline#themes#simple#normal_modified.statusline = [ '#df0000' , '#080808' , 160 , s:bg , '' ] +let g:airline#themes#simple#normal_modified = { + \ 'statusline': [ '#df0000' , '#080808' , 160 , s:bg , '' ] , + \ } let s:I1 = [ '#5fff00' , '#080808' , 82 , s:bg ] let s:I2 = [ '#ff5f00' , '#080808' , 202 , s:bg ] diff --git a/plugin/airline.vim b/plugin/airline.vim index a070675..43a498c 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -44,23 +44,27 @@ let s:airline_highlight_map = { \ } let s:airline_highlight_groups = keys(s:airline_highlight_map) -function! s:highlight(mode) - for key in s:airline_highlight_groups - if exists('g:airline#themes#{g:airline_theme}#{a:mode}[key]') - let colors = g:airline#themes#{g:airline_theme}#{a:mode}[key] - if s:is_win32term - let colors = map(colors, 'v:val != "" && v:val > 128 ? v:val - 128 : v:val') +function! s:highlight(modes) + " always draw the base mode, and then override any/all of the colors with _override + let mapped = map(a:modes, 'v:val == a:modes[0] ? v:val : a:modes[0]."_".v:val') + for mode in mapped + for key in s:airline_highlight_groups + if exists('g:airline#themes#{g:airline_theme}#{mode}[key]') + let colors = g:airline#themes#{g:airline_theme}#{mode}[key] + if s:is_win32term + let colors = map(colors, 'v:val != "" && v:val > 128 ? v:val - 128 : v:val') + endif + let cmd = printf('hi %s %s %s %s %s %s %s', + \ s:airline_highlight_map[key], + \ colors[0] != '' ? 'guifg='.colors[0] : '', + \ colors[1] != '' ? 'guibg='.colors[1] : '', + \ colors[2] != '' ? 'ctermfg='.colors[2] : '', + \ colors[3] != '' ? 'ctermbg='.colors[3] : '', + \ colors[4] != '' ? 'gui='.colors[4] : '', + \ colors[4] != '' ? 'term='.colors[4] : '') + exec cmd endif - let cmd = printf('hi %s %s %s %s %s %s %s', - \ s:airline_highlight_map[key], - \ colors[0] != '' ? 'guifg='.colors[0] : '', - \ colors[1] != '' ? 'guibg='.colors[1] : '', - \ colors[2] != '' ? 'ctermfg='.colors[2] : '', - \ colors[3] != '' ? 'ctermbg='.colors[3] : '', - \ colors[4] != '' ? 'gui='.colors[4] : '', - \ colors[4] != '' ? 'term='.colors[4] : '') - exec cmd - endif + endfor endfor endfunction @@ -131,19 +135,20 @@ function! s:update_statusline(active) call setwinvar(winnr(), '&statusline', sl) endfunction -let s:lastmode = '' +let s:lastmode = [] let g:airline_current_mode_text = '' function! AirlineUpdateHighlight() let l:m = mode() - let l:mode = 'normal' if l:m ==# "i" || l:m ==# "R" - let l:mode = 'insert' + let l:mode = ['insert'] elseif l:m ==? "v" || l:m ==# "" - let l:mode = 'visual' + let l:mode = ['visual'] + else + let l:mode = ['normal'] endif if g:airline_modified_detection && &modified - let l:mode .= '_modified' + call add(l:mode, 'modified') endif if s:lastmode != l:mode @@ -157,7 +162,7 @@ endfunction augroup airline au! - autocmd VimEnter,ColorScheme * call highlight('normal') + autocmd VimEnter,ColorScheme * call highlight(['normal']) autocmd WinLeave * call update_statusline(0) autocmd VimEnter,WinEnter,BufWinEnter * call update_statusline(1) augroup END