themes: load them explicitly rather than implictly
While this adds a bit more code it makes it possible to distinguish between themes not found and errors in themes. Use :verbose AirlineTheme <foobar> to also see the error message in case of errors.
This commit is contained in:
parent
b20e181bc8
commit
14691bb00e
@ -57,19 +57,35 @@ endfunction
|
|||||||
|
|
||||||
" Load an airline theme
|
" Load an airline theme
|
||||||
function! airline#switch_theme(name)
|
function! airline#switch_theme(name)
|
||||||
|
" get all available themes
|
||||||
|
let themes = airline#util#themes('')
|
||||||
|
let err = 0
|
||||||
try
|
try
|
||||||
let palette = g:airline#themes#{a:name}#palette "also lazy loads the theme
|
if index(themes, a:name) == -1
|
||||||
|
" Theme not available
|
||||||
|
call airline#util#warning(printf('The specified theme "%s" cannot be found.', a:name))
|
||||||
|
let err = 1
|
||||||
|
else
|
||||||
|
exe "ru autoload/airline/themes/". a:name. ".vim"
|
||||||
|
endif
|
||||||
let g:airline_theme = a:name
|
let g:airline_theme = a:name
|
||||||
catch
|
catch
|
||||||
echohl WarningMsg | echo 'The specified theme cannot be found.' | echohl NONE
|
call airline#util#warning(printf('There is an error in theme "%s".', a:name))
|
||||||
|
if &vbs
|
||||||
|
call airline#util#warning(v:exception)
|
||||||
|
endif
|
||||||
|
let err = 1
|
||||||
|
endtry
|
||||||
|
|
||||||
|
if err
|
||||||
if exists('g:airline_theme')
|
if exists('g:airline_theme')
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
let g:airline_theme = 'dark'
|
let g:airline_theme = 'dark'
|
||||||
endif
|
endif
|
||||||
endtry
|
endif
|
||||||
|
|
||||||
let w:airline_lastmode = ''
|
unlet! w:airline_lastmode
|
||||||
call airline#load_theme()
|
call airline#load_theme()
|
||||||
|
|
||||||
call airline#util#doautocmd('AirlineAfterTheme')
|
call airline#util#doautocmd('AirlineAfterTheme')
|
||||||
|
Loading…
Reference in New Issue
Block a user