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:
Christian Brabandt 2018-11-13 21:19:01 +01:00
parent b20e181bc8
commit 14691bb00e
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09

View File

@ -57,19 +57,35 @@ endfunction
" Load an airline theme
function! airline#switch_theme(name)
" get all available themes
let themes = airline#util#themes('')
let err = 0
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
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')
return
else
let g:airline_theme = 'dark'
endif
endtry
endif
let w:airline_lastmode = ''
unlet! w:airline_lastmode
call airline#load_theme()
call airline#util#doautocmd('AirlineAfterTheme')