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 b6f368e..f89fd20 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -109,7 +109,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) @@ -126,7 +126,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 @@ -135,7 +135,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)) @@ -148,7 +148,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.vim b/autoload/airline/extensions.vim index 08859f1..f7b7402 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -1,6 +1,28 @@ " 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 + +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 @@ -9,23 +31,10 @@ 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_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 - \ ? (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 +let s:active_winnr = -1 +function! airline#extensions#update_statusline() + let s:active_winnr = winnr() -function! airline#extensions#apply_window_overrides() if &buftype == 'quickfix' let w:airline_section_a = 'Quickfix' let w:airline_section_b = '' @@ -46,28 +55,9 @@ function! airline#extensions#apply_window_overrides() 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', '%{TagbarGenerateStatusline()}') - 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 @@ -97,39 +87,55 @@ 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) - 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) - 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 = ' ' + if exists(':TagbarToggle') + call airline#extensions#tagbar#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')) + if g:airline_enable_branch && (get(g:, 'loaded_fugitive', 0) || get(g:, 'loaded_lawrencium', 0)) + call airline#extensions#branch#init(s:ext) + endif - call airline#extensions#update_external_values() + 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 + + call airline#exec_funcrefs(g:airline_statusline_funcrefs, 0) endfunction diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim new file mode 100644 index 0000000..aa6db6e --- /dev/null +++ b/autoload/airline/extensions/branch.vim @@ -0,0 +1,15 @@ +" MIT license. Copyright (c) 2013 Bailey Ling. +" vim: ts=2 sts=2 sw=2 fdm=indent + +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/autoload/airline/extensions/bufferline.vim b/autoload/airline/extensions/bufferline.vim new file mode 100644 index 0000000..852b33c --- /dev/null +++ b/autoload/airline/extensions/bufferline.vim @@ -0,0 +1,16 @@ +" MIT license. Copyright (c) 2013 Bailey Ling. +" vim: ts=2 sts=2 sw=2 fdm=indent + +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' + let g:bufferline_active_highlight = 'AlBl_active' + let g:bufferline_active_buffer_left = '' + let g:bufferline_active_buffer_right = '' + let g:bufferline_separator = ' ' + + 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/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/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/autoload/airline/extensions/syntastic.vim b/autoload/airline/extensions/syntastic.vim new file mode 100644 index 0000000..d6b386d --- /dev/null +++ b/autoload/airline/extensions/syntastic.vim @@ -0,0 +1,8 @@ +" MIT license. Copyright (c) 2013 Bailey Ling. +" vim: ts=2 sts=2 sw=2 fdm=indent + +function! airline#extensions#syntastic#init(ext) + if g:airline_section_gutter == '' + let g:airline_section_gutter = '%#warningmsg#%{SyntasticStatuslineFlag()}' + endif +endfunction diff --git a/autoload/airline/extensions/tagbar.vim b/autoload/airline/extensions/tagbar.vim new file mode 100644 index 0000000..27fe0b0 --- /dev/null +++ b/autoload/airline/extensions/tagbar.vim @@ -0,0 +1,14 @@ +" 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 + if &ft == 'tagbar' + call airline#extensions#apply_left_override('Tagbar', '%{TagbarGenerateStatusline()}') + endif +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 44631dc..3de3d27 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -48,36 +48,24 @@ call s:check_defined('g:airline_mode_map', { \ '' : 'V-BLOCK', \ }) +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:''}") +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() - let s:active_winnr = winnr() 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', '%{g:airline_externals_branch}') - call s:check_defined('g:airline_section_c', g:airline_externals_bufferline) - 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.']':''}") - 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() 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")') @@ -96,5 +84,4 @@ augroup airline autocmd ColorScheme * call airline#reload_highlight() autocmd WinEnter,BufWinEnter,FileType,BufUnload,ShellCmdPost * \ call on_window_changed() - autocmd CursorMoved * call sync_active_winnr() augroup END