From 3fbdd28e5d41ac89b63609b38012b58e1679a114 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Sat, 17 Aug 2013 17:35:06 +0000 Subject: [PATCH] add profiler. optimize separator highlighting. --- autoload/airline.vim | 12 ++++---- autoload/airline/debug.vim | 15 ++++++++++ autoload/airline/highlighter.vim | 40 ++++++++++++++++----------- autoload/airline/themes/solarized.vim | 2 +- autoload/airline/themes/tomorrow.vim | 2 +- autoload/airline/util.vim | 5 ++-- plugin/airline.vim | 9 +++--- 7 files changed, 55 insertions(+), 30 deletions(-) create mode 100644 autoload/airline/debug.vim diff --git a/autoload/airline.vim b/autoload/airline.vim index 013a446a..14a061e8 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -1,21 +1,20 @@ " MIT License. Copyright (c) 2013 Bailey Ling. -" vim: et ts=2 sts=2 sw=2 fdm=indent +" vim: et ts=2 sts=2 sw=2 let s:sections = ['a','b','c','gutter','x','y','z','warning'] let s:highlighter = airline#highlighter#new() -function! airline#reload_highlight() - call s:highlighter.highlight(['inactive']) - call s:highlighter.highlight(['normal']) +function! airline#load_theme() + call s:highlighter.load_theme() call airline#extensions#load_theme() endfunction -function! airline#load_theme(name) +function! airline#switch_theme(name) let g:airline_theme = a:name let inactive_colors = g:airline#themes#{g:airline_theme}#inactive "also lazy loads the theme let w:airline_lastmode = '' call airline#update_statusline() - call airline#reload_highlight() + call airline#load_theme() call airline#check_mode() endfunction @@ -109,3 +108,4 @@ function! airline#check_mode() endif return '' endfunction + diff --git a/autoload/airline/debug.vim b/autoload/airline/debug.vim new file mode 100644 index 00000000..4e13e9ff --- /dev/null +++ b/autoload/airline/debug.vim @@ -0,0 +1,15 @@ +" MIT License. Copyright (c) 2013 Bailey Ling. +" vim: et ts=2 sts=2 sw=2 + +function! airline#debug#profile() + profile start airline-profile.log + profile func * + profile file * + split + for i in range(1, 50) + wincmd w + redrawstatus + endfor + profile pause + noautocmd qall! +endfunction diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim index 016192e1..f985e8d7 100644 --- a/autoload/airline/highlighter.vim +++ b/autoload/airline/highlighter.vim @@ -1,5 +1,5 @@ -" MIT license. Copyright (c) 2013 Bailey Ling. -" vim: et ts=2 sts=2 sw=2 fdm=indent +" MIT License. Copyright (c) 2013 Bailey Ling. +" vim: et ts=2 sts=2 sw=2 let s:is_win32term = (has('win32') || has('win64')) && !has('gui_running') @@ -19,20 +19,25 @@ function! airline#highlighter#exec(group, colors) \ get(colors, 4, '') != '' ? 'term='.colors[4] : '') endfunction -function! airline#highlighter#exec_separator(from, to) - if a:from == a:to - return a:from - endif +function! airline#highlighter#exec_separator(dict, from, to) let l:from = airline#themes#get_highlight(a:from) let l:to = airline#themes#get_highlight(a:to) let group = a:from.'_to_'.a:to - call airline#highlighter#exec(group, [ l:to[1], l:from[1], l:to[3], l:from[3] ]) - return group + let colors = [ l:to[1], l:from[1], l:to[3], l:from[3] ] + let a:dict[group] = colors + call airline#highlighter#exec(group, colors) endfunction function! airline#highlighter#new() let highlighter = {} let highlighter._separators = [] + let highlighter._init_separators = {} + + function! highlighter.load_theme() + let self._init_separators = {} + call self.highlight(['inactive']) + call self.highlight(['normal']) + endfunction function! highlighter.add_separator(from, to) call add(self._separators, [a:from, a:to]) @@ -44,16 +49,19 @@ function! airline#highlighter#new() let suffix = a:modes[0] == 'inactive' ? '_inactive' : '' for mode in mapped if exists('g:airline#themes#{g:airline_theme}#{mode}') - for key in keys(g:airline#themes#{g:airline_theme}#{mode}) - let colors = g:airline#themes#{g:airline_theme}#{mode}[key] - call airline#highlighter#exec(key.suffix, colors) + let dict = g:airline#themes#{g:airline_theme}#{mode} + for kvp in items(dict) + call airline#highlighter#exec(kvp[0].suffix, kvp[1]) endfor - endif - endfor - " synchronize separator colors - for sep in self._separators - call airline#highlighter#exec_separator(sep[0].suffix, sep[1].suffix) + " initialize separator colors for this mode if necessary + if !has_key(self._init_separators, mode) + let self._init_separators[mode] = 1 + for sep in self._separators + call airline#highlighter#exec_separator(dict, sep[0].suffix, sep[1].suffix) + endfor + endif + endif endfor endfunction diff --git a/autoload/airline/themes/solarized.vim b/autoload/airline/themes/solarized.vim index f6009226..57c82d39 100644 --- a/autoload/airline/themes/solarized.vim +++ b/autoload/airline/themes/solarized.vim @@ -166,5 +166,5 @@ endfunction call s:generate() augroup airline_solarized autocmd! - autocmd ColorScheme * call generate() | call airline#reload_highlight() + autocmd ColorScheme * call generate() | call airline#load_theme() augroup END diff --git a/autoload/airline/themes/tomorrow.vim b/autoload/airline/themes/tomorrow.vim index 41b90eba..b1f86b8f 100644 --- a/autoload/airline/themes/tomorrow.vim +++ b/autoload/airline/themes/tomorrow.vim @@ -39,5 +39,5 @@ endfunction call s:generate() augroup airline_tomorrow autocmd! - autocmd ColorScheme * call generate() | call airline#reload_highlight() + autocmd ColorScheme * call generate() | call airline#load_theme() augroup END diff --git a/autoload/airline/util.vim b/autoload/airline/util.vim index 8372d99d..daa3ea85 100644 --- a/autoload/airline/util.vim +++ b/autoload/airline/util.vim @@ -1,5 +1,5 @@ -" MIT license. Copyright (c) 2013 Bailey Ling. -" vim: ts=2 sts=2 sw=2 fdm=indent +" MIT License. Copyright (c) 2013 Bailey Ling. +" vim: et ts=2 sts=2 sw=2 " for 7.2 compatibility function! airline#util#getwinvar(winnr, key, ...) @@ -22,3 +22,4 @@ function! airline#util#exec_funcrefs(list, break_early) endfor return 0 endfunction + diff --git a/plugin/airline.vim b/plugin/airline.vim index a9eda5ac..5f8755d8 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -1,5 +1,5 @@ " MIT License. Copyright (c) 2013 Bailey Ling. -" vim: et ts=2 sts=2 sw=2 fdm=indent +" vim: et ts=2 sts=2 sw=2 if &cp || v:version < 702 || (exists('g:loaded_airline') && g:loaded_airline) finish @@ -66,7 +66,7 @@ let s:airline_initialized = 0 function! s:on_window_changed() if !s:airline_initialized call airline#extensions#load() - call airline#load_theme(g:airline_theme) + call airline#switch_theme(g:airline_theme) let s:airline_initialized = 1 endif call airline#update_statusline() @@ -95,7 +95,7 @@ function! s:airline_toggle() \ | call on_window_changed() autocmd CmdwinLeave * call remove(g:airline_statusline_funcrefs, -1) - autocmd ColorScheme * call airline#reload_highlight() + autocmd ColorScheme * call airline#load_theme() autocmd WinEnter,BufWinEnter,FileType,BufUnload,ShellCmdPost * \ call on_window_changed() augroup END @@ -111,7 +111,7 @@ function! s:get_airline_themes(a, l, p) endfunction function! s:airline_theme(...) if a:0 - call airline#load_theme(a:1) + call airline#switch_theme(a:1) else echo g:airline_theme endif @@ -121,3 +121,4 @@ command! AirlineToggleWhitespace call airline#extensions#whitespace#toggle() command! AirlineToggle call airline_toggle() call airline_toggle() +