.vimrc: Smartly pick AirlineTheme for certain colorscheme's
authorTony Duckles <tony@nynim.org>
Sat, 13 Jan 2018 13:17:02 +0000
committerTony Duckles <tony@nynim.org>
Wed, 17 Jan 2018 03:57:59 +0000
.vim/bundle/airlinetheme-map/plugin/airlinetheme-map.vim [new file with mode: 0644]
.vimrc

diff --git a/.vim/bundle/airlinetheme-map/plugin/airlinetheme-map.vim b/.vim/bundle/airlinetheme-map/plugin/airlinetheme-map.vim
new file mode 100644 (file)
index 0000000..132111a
--- /dev/null
@@ -0,0 +1,49 @@
+" Customize which :AirlineTheme to use for specific colorscheme's based on
+" caller-supplied mapping table.
+
+" -------------------------------------------------------------------------
+" CONFIGURATION:
+"
+" * Dict providing the mapping table of colorscheme -> airline theme
+"   overrides >
+"   let g:colorscheme_airlinetheme_map = { ... }
+"
+" * Default airline theme to use when no specific entry found in the
+"   mapping table [and no airline theme which exactly matches current
+"   colorscheme] >
+"   let g:colorscheme_airlinetheme_default = [str]
+" -------------------------------------------------------------------------
+
+" Use a ColorScheme autocmd to automatically switch :AirlineTheme based on
+" the new colorscheme.  Defer adding the ColorScheme autocmd until the
+" VimEnter event so that our ColorScheme autocmd hook will be 'last' in the
+" 'autocmd ColorScheme' stack.
+augroup airlinetheme_map_afterinit
+  autocmd!
+  autocmd VimEnter * silent! call <SID>on_init()
+augroup END
+
+function! s:on_init()
+  augroup airlinetheme_map
+    autocmd!
+    autocmd ColorScheme * call <SID>on_colorscheme_change()
+  augroup END
+  call <SID>on_colorscheme_change()
+endfunction
+
+function! s:on_colorscheme_change()
+  " if there's an AirlineTheme override for this colorscheme, use that
+  if exists('g:colorscheme_airlinetheme_map') &&
+        \ has_key(g:colorscheme_airlinetheme_map, g:colors_name)
+    let g:airline_theme=g:colorscheme_airlinetheme_map[g:colors_name]
+    :AirlineRefresh
+  else
+    " if there's an exact-match AirlineTheme for the current colorscheme,
+    " use that; else use the user-defined default AirlineTheme (if any)
+    if exists('g:colorscheme_airlinetheme_default') &&
+          \ g:airline_theme != g:colors_name
+      let g:airline_theme=g:colorscheme_airlinetheme_default
+      :AirlineRefresh
+    endif
+  endif
+endfunction
diff --git a/.vimrc b/.vimrc
index bac407ea15d13fb6fcfe3dddebfa9f22867aa496..d3084a93864bd590132937528ebefd420890238b 100644 (file)
--- a/.vimrc
+++ b/.vimrc
@@ -51,6 +51,7 @@ Plug '~/.vim/bundle/mumps'            " filetype=mumps
 " Other
 Plug 'kopischke/vim-fetch'            " handle opening filenames with line+column numbers
 Plug 'tpope/vim-scriptease'           " misc collection of helper commands
+Plug '~/.vim/bundle/airlinetheme-map' " override AirlineTheme for certain colorscheme's
 Plug '~/.vim/bundle/autofolds'        " folds for my *rc files
 
 call plug#end()
@@ -190,12 +191,23 @@ if &t_Co > 2 || has("gui_running")
     endif
   augroup END
 
+  " colorscheme theme options
   let g:solarized_termcolors=&t_Co    " use 256 colors for solarized
   let g:solarized_termtrans=1
-  colorscheme solarized
 
-  let g:airline_theme='solarized16'   " vim-airline theme
+  if !exists('s:set_colorscheme')
+    colorscheme solarized
+    let s:set_colorscheme=1
+  endif
+
+  " airline theme options
   let g:solarized16_termcolors=16     " always use 16 colors for 'solarized16' vim-airline theme
+  let g:colorscheme_airlinetheme_map = {
+        \ 'seoul256-light': 'zenburn',
+        \ 'solarized': 'solarized16',
+        \ }
+  let g:colorscheme_airlinetheme_default = 'distinguished'
+
 endif
 
 " ----------------------------------------------------------------------------