autoload themes to match colorscheme. resolves #145.

This commit is contained in:
Bailey Ling 2013-08-18 04:44:13 +00:00
parent b4d7531c05
commit 03c08e819c
3 changed files with 44 additions and 5 deletions

View File

@ -20,6 +20,23 @@ function! airline#switch_theme(name)
call airline#check_mode() call airline#check_mode()
endfunction endfunction
function! airline#switch_matching_theme()
let v:errmsg = ''
silent! let palette = g:airline#themes#{g:colors_name}#palette
if empty(v:errmsg)
call airline#switch_theme(g:colors_name)
return 1
else
for map in items(g:airline_theme_map)
if match(g:colors_name, map[0]) > -1
call airline#switch_theme(map[1])
return 1
endif
endfor
endif
return 0
endfunction
function! s:get_section(winnr, key, ...) function! s:get_section(winnr, key, ...)
let text = airline#util#getwinvar(a:winnr, 'airline_section_'.a:key, g:airline_section_{a:key}) let text = airline#util#getwinvar(a:winnr, 'airline_section_'.a:key, g:airline_section_{a:key})
let [prefix, suffix] = [get(a:000, 0, '%( '), get(a:000, 1, ' %)')] let [prefix, suffix] = [get(a:000, 0, '%( '), get(a:000, 1, ' %)')]

View File

@ -61,8 +61,9 @@ values):
only the filename of that buffer. > only the filename of that buffer. >
let g:airline_inactive_collapse=1 let g:airline_inactive_collapse=1
< <
* change the default theme > * themes are automatically selected based on the matching colorscheme. this
let g:airline_theme='dark' can be overridden by defining a value. >
let g:airline_theme=
< <
* enable/disable usage of patched powerline font symbols > * enable/disable usage of patched powerline font symbols >
let g:airline_powerline_fonts=0 let g:airline_powerline_fonts=0

View File

@ -31,7 +31,6 @@ call s:check_defined('g:airline_branch_prefix', exists('g:airline_powerline_font
call s:check_defined('g:airline_readonly_symbol', exists('g:airline_powerline_fonts')?'':'RO') call s:check_defined('g:airline_readonly_symbol', exists('g:airline_powerline_fonts')?'':'RO')
call s:check_defined('g:airline_linecolumn_prefix', exists('g:airline_powerline_fonts')?' ':':') call s:check_defined('g:airline_linecolumn_prefix', exists('g:airline_powerline_fonts')?' ':':')
call s:check_defined('g:airline_paste_symbol', (exists('g:airline_powerline_fonts') ? ' ' : '').'PASTE') call s:check_defined('g:airline_paste_symbol', (exists('g:airline_powerline_fonts') ? ' ' : '').'PASTE')
call s:check_defined('g:airline_theme', 'dark')
call s:check_defined('g:airline_inactive_collapse', 1) call s:check_defined('g:airline_inactive_collapse', 1)
call s:check_defined('g:airline_exclude_filenames', ['DebuggerWatch','DebuggerStack','DebuggerStatus']) call s:check_defined('g:airline_exclude_filenames', ['DebuggerWatch','DebuggerStack','DebuggerStatus'])
call s:check_defined('g:airline_exclude_filetypes', []) call s:check_defined('g:airline_exclude_filetypes', [])
@ -53,6 +52,12 @@ call s:check_defined('g:airline_mode_map', {
\ '' : 'S-BLOCK', \ '' : 'S-BLOCK',
\ }) \ })
call s:check_defined('g:airline_theme_map', {
\ 'Tomorrow.*': 'tomorrow',
\ 'mo[l|n]okai': 'molokai',
\ 'wombat.*': 'wombat',
\ })
call s:check_defined('g:airline_section_a', '%{get(w:, "airline_current_mode", "")}') call s:check_defined('g:airline_section_a', '%{get(w:, "airline_current_mode", "")}')
call s:check_defined('g:airline_section_b', '%{get(w:, "airline_current_branch", "")}') call s:check_defined('g:airline_section_b', '%{get(w:, "airline_current_branch", "")}')
call s:check_defined('g:airline_section_c', '%f%m') call s:check_defined('g:airline_section_c', '%f%m')
@ -63,15 +68,31 @@ call s:check_defined('g:airline_section_z', '%3p%% '.g:airline_linecolumn_prefix
call s:check_defined('g:airline_section_warning', '') call s:check_defined('g:airline_section_warning', '')
let s:airline_initialized = 0 let s:airline_initialized = 0
let s:airline_theme_defined = 0
function! s:on_window_changed() function! s:on_window_changed()
if !s:airline_initialized if !s:airline_initialized
call airline#extensions#load() call airline#extensions#load()
call airline#switch_theme(g:airline_theme)
let s:airline_theme_defined = exists('g:airline_theme')
let g:airline_theme = get(g:, 'airline_theme', 'dark')
call <sid>on_colorscheme_changed()
let s:airline_initialized = 1 let s:airline_initialized = 1
endif endif
call airline#update_statusline() call airline#update_statusline()
endfunction endfunction
function! s:on_colorscheme_changed()
if !s:airline_theme_defined
if airline#switch_matching_theme()
return
endif
endif
" couldn't find a match, or theme was defined, just refresh
call airline#load_theme()
endfunction
function airline#cmdwinenter() function airline#cmdwinenter()
call airline#extensions#apply_left_override('Command Line', '') call airline#extensions#apply_left_override('Command Line', '')
endfunction endfunction
@ -95,7 +116,7 @@ function! s:airline_toggle()
\ | call <sid>on_window_changed() \ | call <sid>on_window_changed()
autocmd CmdwinLeave * call remove(g:airline_statusline_funcrefs, -1) autocmd CmdwinLeave * call remove(g:airline_statusline_funcrefs, -1)
autocmd ColorScheme * call airline#load_theme() autocmd ColorScheme * call <sid>on_colorscheme_changed()
autocmd WinEnter,BufWinEnter,FileType,BufUnload,ShellCmdPost * autocmd WinEnter,BufWinEnter,FileType,BufUnload,ShellCmdPost *
\ call <sid>on_window_changed() \ call <sid>on_window_changed()
augroup END augroup END