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
|
endfunction
|
||||||
|
|
||||||
" Load an airline theme
|
" 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
|
" get all available themes
|
||||||
let themes = airline#util#themes('')
|
let themes = airline#util#themes('')
|
||||||
let err = 0
|
let err = 0
|
||||||
try
|
try
|
||||||
if index(themes, a:name) == -1
|
if index(themes, a:name) == -1
|
||||||
" Theme not available
|
" Theme not available
|
||||||
|
if !silent
|
||||||
call airline#util#warning(printf('The specified theme "%s" cannot be found.', a:name))
|
call airline#util#warning(printf('The specified theme "%s" cannot be found.', a:name))
|
||||||
|
endif
|
||||||
|
throw "not-found"
|
||||||
let err = 1
|
let err = 1
|
||||||
else
|
else
|
||||||
exe "ru autoload/airline/themes/". a:name. ".vim"
|
exe "ru autoload/airline/themes/". a:name. ".vim"
|
||||||
let g:airline_theme = a:name
|
let g:airline_theme = a:name
|
||||||
endif
|
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))
|
call airline#util#warning(printf('There is an error in theme "%s".', a:name))
|
||||||
if &vbs
|
if &vbs
|
||||||
call airline#util#warning(v:exception)
|
call airline#util#warning(v:exception)
|
||||||
@ -100,13 +105,13 @@ function! airline#switch_matching_theme()
|
|||||||
let existing = g:airline_theme
|
let existing = g:airline_theme
|
||||||
let theme = tr(tolower(g:colors_name), '-', '_')
|
let theme = tr(tolower(g:colors_name), '-', '_')
|
||||||
try
|
try
|
||||||
call airline#switch_theme(theme)
|
call airline#switch_theme(theme, 1)
|
||||||
return 1
|
return 1
|
||||||
catch
|
catch
|
||||||
for map in items(g:airline_theme_map)
|
for map in items(g:airline_theme_map)
|
||||||
if match(g:colors_name, map[0]) > -1
|
if match(g:colors_name, map[0]) > -1
|
||||||
try
|
try
|
||||||
call airline#switch_theme(map[1])
|
call airline#switch_theme(map[1], 1)
|
||||||
catch
|
catch
|
||||||
call airline#switch_theme(existing)
|
call airline#switch_theme(existing)
|
||||||
endtry
|
endtry
|
||||||
|
@ -151,7 +151,10 @@ endfunction
|
|||||||
|
|
||||||
function! s:airline_theme(...)
|
function! s:airline_theme(...)
|
||||||
if a:0
|
if a:0
|
||||||
|
try
|
||||||
call airline#switch_theme(a:1)
|
call airline#switch_theme(a:1)
|
||||||
|
catch " discard error
|
||||||
|
endtry
|
||||||
else
|
else
|
||||||
echo g:airline_theme
|
echo g:airline_theme
|
||||||
endif
|
endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user