From ffac12cbbe68577c4431ecabbc9bc142138b01a9 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Wed, 14 Nov 2018 07:36:45 +0100 Subject: [PATCH] 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 --- autoload/airline.vim | 15 ++++++++++----- plugin/airline.vim | 5 ++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/autoload/airline.vim b/autoload/airline.vim index f4f31c3b..eacdc7c1 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -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 diff --git a/plugin/airline.vim b/plugin/airline.vim index 88227e70..3fed71c3 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -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