From 41325bd08cbb91c2ed1530c2114186ef4eac0649 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 6 Aug 2013 00:29:30 +0000 Subject: [PATCH 01/10] extract bufferline into its own file --- autoload/airline/extensions.vim | 8 +------- autoload/airline/extensions/bufferline.vim | 12 ++++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 autoload/airline/extensions/bufferline.vim diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index cd2b880..81aa605 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -117,13 +117,7 @@ function! airline#extensions#load() endif if g:airline_enable_bufferline && get(g:, 'loaded_bufferline', 0) - highlight AlBl_active gui=bold cterm=bold term=bold - highlight link AlBl_inactive Al6 - let g:bufferline_inactive_highlight = 'AlBl_inactive' - let g:bufferline_active_highlight = 'AlBl_active' - let g:bufferline_active_buffer_left = '' - let g:bufferline_active_buffer_right = '' - let g:bufferline_separator = ' ' + call airline#extensions#bufferline#init() endif call add(g:airline_statusline_funcrefs, function('airline#extensions#update_external_values')) diff --git a/autoload/airline/extensions/bufferline.vim b/autoload/airline/extensions/bufferline.vim new file mode 100644 index 0000000..0a42829 --- /dev/null +++ b/autoload/airline/extensions/bufferline.vim @@ -0,0 +1,12 @@ +" MIT license. Copyright (c) 2013 Bailey Ling. +" vim: ts=2 sts=2 sw=2 fdm=indent + +function! airline#extensions#bufferline#init() + highlight AlBl_active gui=bold cterm=bold term=bold + highlight link AlBl_inactive Al6 + let g:bufferline_inactive_highlight = 'AlBl_inactive' + let g:bufferline_active_highlight = 'AlBl_active' + let g:bufferline_active_buffer_left = '' + let g:bufferline_active_buffer_right = '' + let g:bufferline_separator = ' ' +endfunction From f15ac2146f1403ed1465ff8ef4bebeeabd360c32 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 6 Aug 2013 02:44:34 +0000 Subject: [PATCH 02/10] make bufferline almost entirely self contained --- autoload/airline/extensions.vim | 13 ++++++++++--- autoload/airline/extensions/bufferline.vim | 10 +++++++++- plugin/airline.vim | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 81aa605..38414d4 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -1,6 +1,15 @@ " MIT license. Copyright (c) 2013 Bailey Ling. " vim: ts=2 sts=2 sw=2 fdm=indent +let s:ext = {} +let s:ext._cursormove_funcrefs = [] +function! s:ext.add_statusline_funcref(funcref) dict + call add(g:airline_statusline_funcrefs, a:funcref) +endfunction +function! s:ext.add_cursormove_funcref(funcref) dict + call add(self._cursormove_funcrefs, a:funcref) +endfunction + function! airline#extensions#apply_left_override(section1, section2) let w:airline_section_a = a:section1 let w:airline_section_b = a:section2 @@ -10,8 +19,6 @@ function! airline#extensions#apply_left_override(section1, section2) endfunction function! airline#extensions#update_external_values() - let g:airline_externals_bufferline = g:airline_enable_bufferline && exists('*bufferline#get_status_string') - \ ? '%{bufferline#refresh_status()}'.bufferline#get_status_string() : "%f%m" let g:airline_externals_syntastic = g:airline_enable_syntastic && exists('*SyntasticStatuslineFlag') \ ? '%#warningmsg#%{SyntasticStatuslineFlag()}' : '' let g:airline_externals_branch = g:airline_enable_branch @@ -117,7 +124,7 @@ function! airline#extensions#load() endif if g:airline_enable_bufferline && get(g:, 'loaded_bufferline', 0) - call airline#extensions#bufferline#init() + call airline#extensions#bufferline#init(s:ext) endif call add(g:airline_statusline_funcrefs, function('airline#extensions#update_external_values')) diff --git a/autoload/airline/extensions/bufferline.vim b/autoload/airline/extensions/bufferline.vim index 0a42829..84c8a33 100644 --- a/autoload/airline/extensions/bufferline.vim +++ b/autoload/airline/extensions/bufferline.vim @@ -1,7 +1,11 @@ " MIT license. Copyright (c) 2013 Bailey Ling. " vim: ts=2 sts=2 sw=2 fdm=indent -function! airline#extensions#bufferline#init() +function! airline#extensions#bufferline#apply() + let w:airline_section_c = '%{bufferline#refresh_status()}'.bufferline#get_status_string() +endfunction + +function! airline#extensions#bufferline#init(ext) highlight AlBl_active gui=bold cterm=bold term=bold highlight link AlBl_inactive Al6 let g:bufferline_inactive_highlight = 'AlBl_inactive' @@ -9,4 +13,8 @@ function! airline#extensions#bufferline#init() let g:bufferline_active_buffer_left = '' let g:bufferline_active_buffer_right = '' let g:bufferline_separator = ' ' + + if g:airline_enable_bufferline && exists('*bufferline#get_status_string') + call a:ext.add_statusline_funcref(function('airline#extensions#bufferline#apply')) + endif endfunction diff --git a/plugin/airline.vim b/plugin/airline.vim index 7904b74..704ebb2 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -57,7 +57,7 @@ function! s:on_window_changed() call airline#load_theme(g:airline_theme) call s:check_defined('g:airline_section_a', '%{g:airline_current_mode_text}') call s:check_defined('g:airline_section_b', '%{g:airline_externals_branch}') - call s:check_defined('g:airline_section_c', g:airline_externals_bufferline) + call s:check_defined('g:airline_section_c', '%f%m') call s:check_defined('g:airline_section_gutter', g:airline_externals_syntastic) call s:check_defined('g:airline_section_x', g:airline_externals_tagbar."%{strlen(&filetype)>0?&filetype:''}") call s:check_defined('g:airline_section_y', "%{strlen(&fenc)>0?&fenc:''}%{strlen(&ff)>0?'['.&ff.']':''}") From 11fd24b3efa122592085995aabaa37a0b7da9584 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 6 Aug 2013 02:56:30 +0000 Subject: [PATCH 03/10] extract syntastic --- autoload/airline/extensions.vim | 10 ++++++---- autoload/airline/extensions/bufferline.vim | 4 +--- autoload/airline/extensions/commandt.vim | 6 +++++- autoload/airline/extensions/syntastic.vim | 12 ++++++++++++ plugin/airline.vim | 2 +- 5 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 autoload/airline/extensions/syntastic.vim diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 38414d4..d2534cb 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -19,8 +19,6 @@ function! airline#extensions#apply_left_override(section1, section2) endfunction function! airline#extensions#update_external_values() - let g:airline_externals_syntastic = g:airline_enable_syntastic && exists('*SyntasticStatuslineFlag') - \ ? '%#warningmsg#%{SyntasticStatuslineFlag()}' : '' let g:airline_externals_branch = g:airline_enable_branch \ ? (exists('*fugitive#head') && strlen(fugitive#head()) > 0 \ ? g:airline_branch_prefix.fugitive#head() @@ -120,10 +118,14 @@ function! airline#extensions#load() endif if get(g:, 'command_t_loaded', 0) - call add(g:airline_statusline_funcrefs, function('airline#extensions#commandt#apply_window_override')) + call airline#extensions#commandt#init(s:ext) endif - if g:airline_enable_bufferline && get(g:, 'loaded_bufferline', 0) + if g:airline_enable_syntastic && get(g:, 'loaded_syntastic_plugin') + call airline#extensions#syntastic#init(s:ext) + endif + + if g:airline_enable_bufferline && exists('*bufferline#get_status_string') call airline#extensions#bufferline#init(s:ext) endif diff --git a/autoload/airline/extensions/bufferline.vim b/autoload/airline/extensions/bufferline.vim index 84c8a33..6bed416 100644 --- a/autoload/airline/extensions/bufferline.vim +++ b/autoload/airline/extensions/bufferline.vim @@ -14,7 +14,5 @@ function! airline#extensions#bufferline#init(ext) let g:bufferline_active_buffer_right = '' let g:bufferline_separator = ' ' - if g:airline_enable_bufferline && exists('*bufferline#get_status_string') - call a:ext.add_statusline_funcref(function('airline#extensions#bufferline#apply')) - endif + call a:ext.add_statusline_funcref(function('airline#extensions#bufferline#apply')) endfunction diff --git a/autoload/airline/extensions/commandt.vim b/autoload/airline/extensions/commandt.vim index 6ade032..2c55675 100644 --- a/autoload/airline/extensions/commandt.vim +++ b/autoload/airline/extensions/commandt.vim @@ -1,8 +1,12 @@ " MIT license. Copyright (c) 2013 Bailey Ling. " vim: ts=2 sts=2 sw=2 fdm=indent -function! airline#extensions#commandt#apply_window_override() +function! airline#extensions#commandt#apply() if bufname('%') ==# 'GoToFile' call airline#extensions#apply_left_override('CommandT', '') endif endfunction + +function! airline#extensions#commandt#init(ext) + call ext.add_statusline_funcref(function('airline#extensions#commandt#apply')) +endfunction diff --git a/autoload/airline/extensions/syntastic.vim b/autoload/airline/extensions/syntastic.vim new file mode 100644 index 0000000..f77cfd6 --- /dev/null +++ b/autoload/airline/extensions/syntastic.vim @@ -0,0 +1,12 @@ +" MIT license. Copyright (c) 2013 Bailey Ling. +" vim: ts=2 sts=2 sw=2 fdm=indent + +function! airline#extensions#syntastic#apply() + let w:airline_section_gutter = '%#warningmsg#%{SyntasticStatuslineFlag()}' +endfunction + +function! airline#extensions#syntastic#init(ext) + if g:airline_enable_syntastic && exists('*SyntasticStatuslineFlag') + call a:ext.add_statusline_funcref(function('airline#extensions#syntastic#apply')) + endif +endfunction diff --git a/plugin/airline.vim b/plugin/airline.vim index 704ebb2..537b2b1 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -58,7 +58,7 @@ function! s:on_window_changed() call s:check_defined('g:airline_section_a', '%{g:airline_current_mode_text}') call s:check_defined('g:airline_section_b', '%{g:airline_externals_branch}') call s:check_defined('g:airline_section_c', '%f%m') - call s:check_defined('g:airline_section_gutter', g:airline_externals_syntastic) + call s:check_defined('g:airline_section_gutter', '') call s:check_defined('g:airline_section_x', g:airline_externals_tagbar."%{strlen(&filetype)>0?&filetype:''}") call s:check_defined('g:airline_section_y', "%{strlen(&fenc)>0?&fenc:''}%{strlen(&ff)>0?'['.&ff.']':''}") call s:check_defined('g:airline_section_z', '%3p%% '.g:airline_linecolumn_prefix.'%3l:%3c') From 9c960875fe5433f26bfe67ee789a1e67aee147ee Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 6 Aug 2013 03:07:01 +0000 Subject: [PATCH 04/10] extract fugitive/lawrencium --- autoload/airline/extensions.vim | 11 ++++------- autoload/airline/extensions/branch.vim | 16 ++++++++++++++++ plugin/airline.vim | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 autoload/airline/extensions/branch.vim diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index d2534cb..891007d 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -19,13 +19,6 @@ function! airline#extensions#apply_left_override(section1, section2) endfunction function! airline#extensions#update_external_values() - let g:airline_externals_branch = g:airline_enable_branch - \ ? (exists('*fugitive#head') && strlen(fugitive#head()) > 0 - \ ? g:airline_branch_prefix.fugitive#head() - \ : exists('*lawrencium#statusline') && strlen(lawrencium#statusline()) > 0 - \ ? g:airline_branch_prefix.lawrencium#statusline() - \ : '') - \ : '' let g:airline_externals_tagbar = g:airline_enable_tagbar && exists(':Tagbar') \ ? '%(%{tagbar#currenttag("%s","")} '.g:airline_right_alt_sep.' %)' : '' endfunction @@ -121,6 +114,10 @@ function! airline#extensions#load() call airline#extensions#commandt#init(s:ext) endif + if g:airline_enable_branch && (get(g:, 'loaded_fugitive', 0) || get(g:, 'loaded_lawrencium', 0)) + call airline#extensions#branch#init(s:ext) + endif + if g:airline_enable_syntastic && get(g:, 'loaded_syntastic_plugin') call airline#extensions#syntastic#init(s:ext) endif diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim new file mode 100644 index 0000000..08a0687 --- /dev/null +++ b/autoload/airline/extensions/branch.vim @@ -0,0 +1,16 @@ +" MIT license. Copyright (c) 2013 Bailey Ling. +" vim: ts=2 sts=2 sw=2 fdm=indent + +function! airline#extensions#branch#apply() + let w:airline_section_b = + \ exists('*fugitive#head') && strlen(fugitive#head()) > 0 + \ ? g:airline_branch_prefix.fugitive#head() + \ : exists('*lawrencium#statusline') && strlen(lawrencium#statusline()) > 0 + \ ? g:airline_branch_prefix.lawrencium#statusline() + \ : '' +endfunction + +function! airline#extensions#branch#init(ext) + call a:ext.add_statusline_funcref(function('airline#extensions#branch#apply')) +endfunction + diff --git a/plugin/airline.vim b/plugin/airline.vim index 537b2b1..745f214 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -56,7 +56,7 @@ function! s:on_window_changed() call airline#extensions#load() call airline#load_theme(g:airline_theme) call s:check_defined('g:airline_section_a', '%{g:airline_current_mode_text}') - call s:check_defined('g:airline_section_b', '%{g:airline_externals_branch}') + call s:check_defined('g:airline_section_b', '') call s:check_defined('g:airline_section_c', '%f%m') call s:check_defined('g:airline_section_gutter', '') call s:check_defined('g:airline_section_x', g:airline_externals_tagbar."%{strlen(&filetype)>0?&filetype:''}") From 48f0e3652c7918685b53356abab984d059558f1f Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 6 Aug 2013 03:16:49 +0000 Subject: [PATCH 05/10] extract tagbar --- autoload/airline/extensions.vim | 10 ++++------ autoload/airline/extensions/tagbar.vim | 11 +++++++++++ plugin/airline.vim | 15 ++++++++------- 3 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 autoload/airline/extensions/tagbar.vim diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 891007d..9efa679 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -18,11 +18,6 @@ function! airline#extensions#apply_left_override(section1, section2) let w:airline_left_only = 1 endfunction -function! airline#extensions#update_external_values() - let g:airline_externals_tagbar = g:airline_enable_tagbar && exists(':Tagbar') - \ ? '%(%{tagbar#currenttag("%s","")} '.g:airline_right_alt_sep.' %)' : '' -endfunction - function! airline#extensions#apply_window_overrides() if &buftype == 'quickfix' let w:airline_section_a = 'Quickfix' @@ -114,6 +109,10 @@ function! airline#extensions#load() call airline#extensions#commandt#init(s:ext) endif + if get(g:, 'loaded_tagbar', 0) + call airline#extensions#tagbar#init(s:ext) + endif + if g:airline_enable_branch && (get(g:, 'loaded_fugitive', 0) || get(g:, 'loaded_lawrencium', 0)) call airline#extensions#branch#init(s:ext) endif @@ -126,7 +125,6 @@ function! airline#extensions#load() call airline#extensions#bufferline#init(s:ext) endif - call add(g:airline_statusline_funcrefs, function('airline#extensions#update_external_values')) call add(g:airline_statusline_funcrefs, function('airline#extensions#apply_window_overrides')) call add(g:airline_exclude_funcrefs, function('airline#extensions#is_excluded_window')) diff --git a/autoload/airline/extensions/tagbar.vim b/autoload/airline/extensions/tagbar.vim new file mode 100644 index 0000000..8131652 --- /dev/null +++ b/autoload/airline/extensions/tagbar.vim @@ -0,0 +1,11 @@ +" MIT license. Copyright (c) 2013 Bailey Ling. +" vim: ts=2 sts=2 sw=2 fdm=indent + +function! airline#extensions#tagbar#apply() + let w:airline_section_x = '%(%{tagbar#currenttag("%s","")} '.g:airline_right_alt_sep.' %)'.g:airline_section_x +endfunction + +function! airline#extensions#tagbar#init(ext) + call a:ext.add_statusline_funcref(function('airline#extensions#tagbar#apply')) +endfunction + diff --git a/plugin/airline.vim b/plugin/airline.vim index 745f214..e637ce6 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -48,6 +48,14 @@ call s:check_defined('g:airline_mode_map', { \ '' : 'V-BLOCK', \ }) +call s:check_defined('g:airline_section_a', '%{g:airline_current_mode_text}') +call s:check_defined('g:airline_section_b', '') +call s:check_defined('g:airline_section_c', '%f%m') +call s:check_defined('g:airline_section_gutter', '') +call s:check_defined('g:airline_section_x', "%{strlen(&filetype)>0?&filetype:''}") +call s:check_defined('g:airline_section_y', "%{strlen(&fenc)>0?&fenc:''}%{strlen(&ff)>0?'['.&ff.']':''}") +call s:check_defined('g:airline_section_z', '%3p%% '.g:airline_linecolumn_prefix.'%3l:%3c') + let s:airline_initialized = 0 let s:active_winnr = -1 function! s:on_window_changed() @@ -55,13 +63,6 @@ function! s:on_window_changed() if !s:airline_initialized call airline#extensions#load() call airline#load_theme(g:airline_theme) - call s:check_defined('g:airline_section_a', '%{g:airline_current_mode_text}') - call s:check_defined('g:airline_section_b', '') - call s:check_defined('g:airline_section_c', '%f%m') - call s:check_defined('g:airline_section_gutter', '') - call s:check_defined('g:airline_section_x', g:airline_externals_tagbar."%{strlen(&filetype)>0?&filetype:''}") - call s:check_defined('g:airline_section_y', "%{strlen(&fenc)>0?&fenc:''}%{strlen(&ff)>0?'['.&ff.']':''}") - call s:check_defined('g:airline_section_z', '%3p%% '.g:airline_linecolumn_prefix.'%3l:%3c') let s:airline_initialized = 1 endif call airline#update_statusline() From 98f3d13705dd5485cdd76ae2095e0489eb9e7177 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 6 Aug 2013 03:33:25 +0000 Subject: [PATCH 06/10] do not overwrite when left only --- autoload/airline/extensions/branch.vim | 3 +++ autoload/airline/extensions/bufferline.vim | 3 +++ 2 files changed, 6 insertions(+) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index 08a0687..feac6ff 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -2,6 +2,9 @@ " vim: ts=2 sts=2 sw=2 fdm=indent function! airline#extensions#branch#apply() + if exists('w:airline_left_only') + return + endif let w:airline_section_b = \ exists('*fugitive#head') && strlen(fugitive#head()) > 0 \ ? g:airline_branch_prefix.fugitive#head() diff --git a/autoload/airline/extensions/bufferline.vim b/autoload/airline/extensions/bufferline.vim index 6bed416..55fda12 100644 --- a/autoload/airline/extensions/bufferline.vim +++ b/autoload/airline/extensions/bufferline.vim @@ -2,6 +2,9 @@ " vim: ts=2 sts=2 sw=2 fdm=indent function! airline#extensions#bufferline#apply() + if exists('w:airline_left_only') + return + endif let w:airline_section_c = '%{bufferline#refresh_status()}'.bufferline#get_status_string() endfunction From ac211a58eb010fa883251c0e384ae1a3a2f3f5a4 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 6 Aug 2013 03:34:45 +0000 Subject: [PATCH 07/10] extract all plugin related functionality out of the core --- README.md | 2 +- autoload/airline.vim | 6 ++--- autoload/airline/extensions.vim | 32 +++++++++++++++++++-------- autoload/airline/extensions/ctrlp.vim | 18 ++++++++++----- plugin/airline.vim | 14 ------------ 5 files changed, 39 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 8513c64..4df3561 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Lean & mean statusline for vim that's light as air. * looks good with regular fonts and provides configuration points so you can use unicode or powerline symbols. * optimized for speed; it loads in under a millisecond. * fully customizable; if you know a little `statusline` syntax you can tweak it to your needs. -* extensive suite of themes for popular colorschemes including [solarized][23] (dark and light), [tomorrow][24] (all variants), [molokai][25], [jellybeans][26] and others. +* extensive suite of themes for popular colorschemes including [solarized][23] (dark and light), [tomorrow][24] (all variants), [molokai][25], [jellybeans][26] and others; have a look at the [screenshots][14] in the wiki. * supports 7.2 as the minimum Vim version # Rationale diff --git a/autoload/airline.vim b/autoload/airline.vim index 52d2522..113ec31 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -104,7 +104,7 @@ function! s:get_statusline(winnr, active) return sl endfunction -function! s:exec_funcrefs(list, break_early) +function! airline#exec_funcrefs(list, break_early) " for 7.2; we cannot iterate list, hence why we use range() " for 7.3-[97, 328]; we cannot reuse the variable, hence the {} for i in range(0, len(a:list) - 1) @@ -121,7 +121,7 @@ function! s:exec_funcrefs(list, break_early) endfunction function! airline#update_statusline() - if s:exec_funcrefs(g:airline_exclude_funcrefs, 1) + if airline#exec_funcrefs(g:airline_exclude_funcrefs, 1) call setwinvar(winnr(), '&statusline', '') return endif @@ -130,7 +130,7 @@ function! airline#update_statusline() for section in s:sections unlet! w:airline_section_{section} endfor - call s:exec_funcrefs(g:airline_statusline_funcrefs, 0) + call airline#exec_funcrefs(g:airline_statusline_funcrefs, 0) let w:airline_active = 1 call setwinvar(winnr(), '&statusline', s:get_statusline(winnr(), 1)) diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 9efa679..01225d8 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -18,7 +18,10 @@ function! airline#extensions#apply_left_override(section1, section2) let w:airline_left_only = 1 endfunction -function! airline#extensions#apply_window_overrides() +let s:active_winnr = -1 +function! airline#extensions#update_statusline() + let s:active_winnr = winnr() + if &buftype == 'quickfix' let w:airline_section_a = 'Quickfix' let w:airline_section_b = '' @@ -90,19 +93,33 @@ function! airline#extensions#load_theme() endif endfunction +function! s:sync_active_winnr() + if winnr() != s:active_winnr + if airline#exec_funcrefs(s:ext._cursormove_funcrefs, 1) + return + endif + call airline#update_statusline() + endif +endfunction + function! airline#extensions#load() + " non-trivial number of external plugins use eventignore=all, so we need to account for that + autocmd CursorMoved * call sync_active_winnr() + + " load core funcrefs + call add(g:airline_exclude_funcrefs, function('airline#extensions#is_excluded_window')) + call add(g:airline_statusline_funcrefs, function('airline#extensions#update_statusline')) + if get(g:, 'loaded_unite', 0) let g:unite_force_overwrite_statusline = 0 endif + if get(g:, 'loaded_vimfiler', 0) let g:vimfiler_force_overwrite_statusline = 0 endif if get(g:, 'loaded_ctrlp', 0) - let g:ctrlp_status_func = { - \ 'main': 'airline#extensions#ctrlp#ctrlp_airline', - \ 'prog': 'airline#extensions#ctrlp#ctrlp_airline_status', - \ } + call airline#extensions#ctrlp#init(s:ext) endif if get(g:, 'command_t_loaded', 0) @@ -125,9 +142,6 @@ function! airline#extensions#load() call airline#extensions#bufferline#init(s:ext) endif - call add(g:airline_statusline_funcrefs, function('airline#extensions#apply_window_overrides')) - call add(g:airline_exclude_funcrefs, function('airline#extensions#is_excluded_window')) - - call airline#extensions#update_external_values() + call airline#exec_funcrefs(g:airline_statusline_funcrefs, 0) endfunction diff --git a/autoload/airline/extensions/ctrlp.vim b/autoload/airline/extensions/ctrlp.vim index a082e57..b5f0ea3 100644 --- a/autoload/airline/extensions/ctrlp.vim +++ b/autoload/airline/extensions/ctrlp.vim @@ -26,10 +26,7 @@ function! airline#extensions#ctrlp#load_theme() endfor endfunction -" Recreate Ctrl-P status line with some slight modifications - " Arguments: focus, byfname, s:regexp, prv, item, nxt, marked -" a:1 a:2 a:3 a:4 a:5 a:6 a:7 function! airline#extensions#ctrlp#ctrlp_airline(...) let regex = a:3 ? '%#CtrlPlight# regex %*' : '' let prv = '%#CtrlPlight# '.a:4.' %#Ctrlparrow1#'.g:airline_left_sep @@ -39,15 +36,24 @@ function! airline#extensions#ctrlp#ctrlp_airline(...) let focus = '%=%<%#CtrlPdark# '.a:1.' %*' let byfname = '%#CtrlParrow3#'.g:airline_right_alt_sep.'%#CtrlPdark# '.a:2.' %*' let dir = '%#CtrlParrow3#'.g:airline_right_sep.'%#CtrlPlight# '.getcwd().' %*' - " Return the full statusline return regex.prv.item.nxt.marked.focus.byfname.dir endfunction " Argument: len -" a:1 function! airline#extensions#ctrlp#ctrlp_airline_status(...) let len = '%#CtrlPdark# '.a:1 let dir = '%=%<%#CtrlParrow3#'.g:airline_right_sep.'%#CtrlPlight# '.getcwd().' %*' - " Return the full statusline return len.dir endfunction + +function! airline#extensions#ctrlp#is_statusline_overwritten() + return match(&statusline, 'CtrlPlight') >= 0 +endfunction + +function! airline#extensions#ctrlp#init(ext) + let g:ctrlp_status_func = { + \ 'main': 'airline#extensions#ctrlp#ctrlp_airline', + \ 'prog': 'airline#extensions#ctrlp#ctrlp_airline_status', + \ } + call a:ext.add_cursormove_funcref(function('airline#extensions#ctrlp#is_statusline_overwritten')) +endfunction diff --git a/plugin/airline.vim b/plugin/airline.vim index e637ce6..cfd6197 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -57,9 +57,7 @@ call s:check_defined('g:airline_section_y', "%{strlen(&fenc)>0?&fenc:''}%{strlen call s:check_defined('g:airline_section_z', '%3p%% '.g:airline_linecolumn_prefix.'%3l:%3c') let s:airline_initialized = 0 -let s:active_winnr = -1 function! s:on_window_changed() - let s:active_winnr = winnr() if !s:airline_initialized call airline#extensions#load() call airline#load_theme(g:airline_theme) @@ -68,17 +66,6 @@ function! s:on_window_changed() call airline#update_statusline() endfunction -" non-trivial number of external plugins use eventignore=all, so we need to account for that -function! s:sync_active_winnr() - if winnr() != s:active_winnr - " prevent ctrlp statusline from getting overwritten - if get(g:, 'loaded_ctrlp', 0) && match(&statusline, 'CtrlPlight') >= 0 - return - endif - call s:on_window_changed() - endif -endfunction - function! s:get_airline_themes(a, l, p) let files = split(globpath(&rtp, 'autoload/airline/themes/'.a:a.'*'), "\n") return map(files, 'fnamemodify(v:val, ":t:r")') @@ -97,5 +84,4 @@ augroup airline autocmd ColorScheme * call airline#highlight(['normal']) autocmd WinEnter,BufWinEnter,FileType,BufUnload,ShellCmdPost * \ call on_window_changed() - autocmd CursorMoved * call sync_active_winnr() augroup END From 8677fa875b083e30862ca95bda722756626178af Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 6 Aug 2013 03:56:20 +0000 Subject: [PATCH 08/10] minor optimization --- autoload/airline/extensions.vim | 38 +++++++++++--------------- autoload/airline/extensions/tagbar.vim | 3 ++ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 01225d8..880da2b 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -10,6 +10,19 @@ function! s:ext.add_cursormove_funcref(funcref) dict call add(self._cursormove_funcrefs, a:funcref) endfunction +let s:filetype_overrides = { + \ 'netrw': [ 'netrw', '%f' ], + \ 'unite': [ 'Unite', '%{unite#get_status_string()}' ], + \ 'nerdtree': [ 'NERD', '' ], + \ 'undotree': [ 'undotree', '' ], + \ 'gundo': [ 'Gundo', '' ], + \ 'diff': [ 'diff', '' ], + \ 'vimshell': [ 'vimshell', '%{vimshell#get_status_string()}' ], + \ 'vimfiler': [ 'vimfiler', '%{vimfiler#get_status_string()}' ], + \ 'minibufexpl': [ 'MiniBufExplorer', '' ], + \ 'startify': [ 'startify', '' ], + \ } + function! airline#extensions#apply_left_override(section1, section2) let w:airline_section_a = a:section1 let w:airline_section_b = a:section2 @@ -42,28 +55,9 @@ function! airline#extensions#update_statusline() let w:airline_section_c = bufname(winbufnr(winnr())) endif - if &ft == 'netrw' - call airline#extensions#apply_left_override('netrw', '%f') - elseif &ft == 'unite' - call airline#extensions#apply_left_override('Unite', '%{unite#get_status_string()}') - elseif &ft == 'nerdtree' - call airline#extensions#apply_left_override('NERD', '') - elseif &ft == 'undotree' - call airline#extensions#apply_left_override('undotree', '') - elseif &ft == 'gundo' - call airline#extensions#apply_left_override('Gundo', '') - elseif &ft == 'diff' - call airline#extensions#apply_left_override('diff', '') - elseif &ft == 'tagbar' - call airline#extensions#apply_left_override('Tagbar', '') - elseif &ft == 'vimshell' - call airline#extensions#apply_left_override('vimshell', '%{vimshell#get_status_string()}') - elseif &ft == 'vimfiler' - call airline#extensions#apply_left_override('vimfiler', '%{vimfiler#get_status_string()}') - elseif &ft == 'minibufexpl' - call airline#extensions#apply_left_override('MiniBufExplorer', '') - elseif &ft == 'startify' - call airline#extensions#apply_left_override('startify', '') + if has_key(s:filetype_overrides, &ft) + let args = s:filetype_overrides[&ft] + call airline#extensions#apply_left_override(args[0], args[1]) endif endfunction diff --git a/autoload/airline/extensions/tagbar.vim b/autoload/airline/extensions/tagbar.vim index 8131652..bf38567 100644 --- a/autoload/airline/extensions/tagbar.vim +++ b/autoload/airline/extensions/tagbar.vim @@ -3,6 +3,9 @@ function! airline#extensions#tagbar#apply() let w:airline_section_x = '%(%{tagbar#currenttag("%s","")} '.g:airline_right_alt_sep.' %)'.g:airline_section_x + if &ft == 'tagbar' + call airline#extensions#apply_left_override('Tagbar', '') + endif endfunction function! airline#extensions#tagbar#init(ext) From 990e3fc9492140c0f6287ebc812ea384892744b2 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 6 Aug 2013 00:35:07 -0400 Subject: [PATCH 09/10] make branch/bufferline default statusline rather than overrides --- autoload/airline/extensions/branch.vim | 21 ++++++++------------- autoload/airline/extensions/bufferline.vim | 11 +++-------- autoload/airline/extensions/syntastic.vim | 8 ++------ 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index feac6ff..4b35e46 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -1,19 +1,14 @@ " MIT license. Copyright (c) 2013 Bailey Ling. " vim: ts=2 sts=2 sw=2 fdm=indent -function! airline#extensions#branch#apply() - if exists('w:airline_left_only') - return - endif - let w:airline_section_b = - \ exists('*fugitive#head') && strlen(fugitive#head()) > 0 - \ ? g:airline_branch_prefix.fugitive#head() - \ : exists('*lawrencium#statusline') && strlen(lawrencium#statusline()) > 0 - \ ? g:airline_branch_prefix.lawrencium#statusline() - \ : '' -endfunction - function! airline#extensions#branch#init(ext) - call a:ext.add_statusline_funcref(function('airline#extensions#branch#apply')) + if g:airline_section_b == '' + let g:airline_section_b = + \ exists('*fugitive#head') && strlen(fugitive#head()) > 0 + \ ? g:airline_branch_prefix.fugitive#head() + \ : exists('*lawrencium#statusline') && strlen(lawrencium#statusline()) > 0 + \ ? g:airline_branch_prefix.lawrencium#statusline() + \ : '' + endif endfunction diff --git a/autoload/airline/extensions/bufferline.vim b/autoload/airline/extensions/bufferline.vim index 55fda12..852b33c 100644 --- a/autoload/airline/extensions/bufferline.vim +++ b/autoload/airline/extensions/bufferline.vim @@ -1,13 +1,6 @@ " MIT license. Copyright (c) 2013 Bailey Ling. " vim: ts=2 sts=2 sw=2 fdm=indent -function! airline#extensions#bufferline#apply() - if exists('w:airline_left_only') - return - endif - let w:airline_section_c = '%{bufferline#refresh_status()}'.bufferline#get_status_string() -endfunction - function! airline#extensions#bufferline#init(ext) highlight AlBl_active gui=bold cterm=bold term=bold highlight link AlBl_inactive Al6 @@ -17,5 +10,7 @@ function! airline#extensions#bufferline#init(ext) let g:bufferline_active_buffer_right = '' let g:bufferline_separator = ' ' - call a:ext.add_statusline_funcref(function('airline#extensions#bufferline#apply')) + if g:airline_section_c == '%f%m' + let g:airline_section_c = '%{bufferline#refresh_status()}'.bufferline#get_status_string() + endif endfunction diff --git a/autoload/airline/extensions/syntastic.vim b/autoload/airline/extensions/syntastic.vim index f77cfd6..d6b386d 100644 --- a/autoload/airline/extensions/syntastic.vim +++ b/autoload/airline/extensions/syntastic.vim @@ -1,12 +1,8 @@ " MIT license. Copyright (c) 2013 Bailey Ling. " vim: ts=2 sts=2 sw=2 fdm=indent -function! airline#extensions#syntastic#apply() - let w:airline_section_gutter = '%#warningmsg#%{SyntasticStatuslineFlag()}' -endfunction - function! airline#extensions#syntastic#init(ext) - if g:airline_enable_syntastic && exists('*SyntasticStatuslineFlag') - call a:ext.add_statusline_funcref(function('airline#extensions#syntastic#apply')) + if g:airline_section_gutter == '' + let g:airline_section_gutter = '%#warningmsg#%{SyntasticStatuslineFlag()}' endif endfunction From e858eaa99016516a1490b0bea1ecc25df7bb3b81 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 6 Aug 2013 00:42:59 -0400 Subject: [PATCH 10/10] fix branch detection --- autoload/airline.vim | 1 - autoload/airline/extensions/branch.vim | 19 ++++++++++--------- plugin/airline.vim | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/autoload/airline.vim b/autoload/airline.vim index 113ec31..81255e4 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -143,7 +143,6 @@ function! airline#update_statusline() endfor endfunction -let g:airline_current_mode_text = '' function! airline#update_highlight() if get(w:, 'airline_active', 1) let l:m = mode() diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index 4b35e46..aa6db6e 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -1,14 +1,15 @@ " MIT license. Copyright (c) 2013 Bailey Ling. " vim: ts=2 sts=2 sw=2 fdm=indent -function! airline#extensions#branch#init(ext) - if g:airline_section_b == '' - let g:airline_section_b = - \ exists('*fugitive#head') && strlen(fugitive#head()) > 0 - \ ? g:airline_branch_prefix.fugitive#head() - \ : exists('*lawrencium#statusline') && strlen(lawrencium#statusline()) > 0 - \ ? g:airline_branch_prefix.lawrencium#statusline() - \ : '' - endif +function! airline#extensions#branch#apply() + let g:airline_current_branch = exists('*fugitive#head') && strlen(fugitive#head()) > 0 + \ ? g:airline_branch_prefix.fugitive#head() + \ : exists('*lawrencium#statusline') && strlen(lawrencium#statusline()) > 0 + \ ? g:airline_branch_prefix.lawrencium#statusline() + \ : '' +endfunction + +function! airline#extensions#branch#init(ext) + call a:ext.add_statusline_funcref(function('airline#extensions#branch#apply')) endfunction diff --git a/plugin/airline.vim b/plugin/airline.vim index cfd6197..455b9fc 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -48,8 +48,8 @@ call s:check_defined('g:airline_mode_map', { \ '' : 'V-BLOCK', \ }) -call s:check_defined('g:airline_section_a', '%{g:airline_current_mode_text}') -call s:check_defined('g:airline_section_b', '') +call s:check_defined('g:airline_section_a', '%{get(g:, "airline_current_mode_text", "")}') +call s:check_defined('g:airline_section_b', '%{get(g:, "airline_current_branch", "")}') call s:check_defined('g:airline_section_c', '%f%m') call s:check_defined('g:airline_section_gutter', '') call s:check_defined('g:airline_section_x', "%{strlen(&filetype)>0?&filetype:''}")