mirror of
https://github.com/vim-airline/vim-airline.git
synced 2024-11-22 14:49:06 +08:00
theme: do not show not-found warning
Only show the "airline theme not found" warning message, when the user actually used `:AirlineTheme foobar`, not when called by an autocommand that tries to switch themes when the Vim colorscheme changed. fixes #1824
This commit is contained in:
parent
b2e1dbad6f
commit
ffac12cbbe
|
@ -56,20 +56,25 @@ function! airline#load_theme()
|
|||
endfunction
|
||||
|
||||
" Load an airline theme
|
||||
function! airline#switch_theme(name)
|
||||
function! airline#switch_theme(name, ...)
|
||||
let silent = get(a:000, '0', 0)
|
||||
" get all available themes
|
||||
let themes = airline#util#themes('')
|
||||
let err = 0
|
||||
try
|
||||
if index(themes, a:name) == -1
|
||||
" Theme not available
|
||||
call airline#util#warning(printf('The specified theme "%s" cannot be found.', a:name))
|
||||
if !silent
|
||||
call airline#util#warning(printf('The specified theme "%s" cannot be found.', a:name))
|
||||
endif
|
||||
throw "not-found"
|
||||
let err = 1
|
||||
else
|
||||
exe "ru autoload/airline/themes/". a:name. ".vim"
|
||||
let g:airline_theme = a:name
|
||||
endif
|
||||
catch
|
||||
catch /^Vim/
|
||||
" catch only Vim errors, not "not-found"
|
||||
call airline#util#warning(printf('There is an error in theme "%s".', a:name))
|
||||
if &vbs
|
||||
call airline#util#warning(v:exception)
|
||||
|
@ -100,13 +105,13 @@ function! airline#switch_matching_theme()
|
|||
let existing = g:airline_theme
|
||||
let theme = tr(tolower(g:colors_name), '-', '_')
|
||||
try
|
||||
call airline#switch_theme(theme)
|
||||
call airline#switch_theme(theme, 1)
|
||||
return 1
|
||||
catch
|
||||
for map in items(g:airline_theme_map)
|
||||
if match(g:colors_name, map[0]) > -1
|
||||
try
|
||||
call airline#switch_theme(map[1])
|
||||
call airline#switch_theme(map[1], 1)
|
||||
catch
|
||||
call airline#switch_theme(existing)
|
||||
endtry
|
||||
|
|
|
@ -151,7 +151,10 @@ endfunction
|
|||
|
||||
function! s:airline_theme(...)
|
||||
if a:0
|
||||
call airline#switch_theme(a:1)
|
||||
try
|
||||
call airline#switch_theme(a:1)
|
||||
catch " discard error
|
||||
endtry
|
||||
else
|
||||
echo g:airline_theme
|
||||
endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user