mirror of
https://github.com/vim-airline/vim-airline.git
synced 2025-02-20 17:52:45 +08:00
extract all plugin related functionality out of the core
This commit is contained in:
parent
98f3d13705
commit
ac211a58eb
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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 <sid>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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 <sid>on_window_changed()
|
||||
autocmd CursorMoved * call <sid>sync_active_winnr()
|
||||
augroup END
|
||||
|
Loading…
x
Reference in New Issue
Block a user