From 6c66ad5dfc47a17fea78290973c22562781e7f8a Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 1 Oct 2013 21:23:17 -0400 Subject: [PATCH] refactor ctrlp statusline to use builder. resolves #291. --- autoload/airline/builder.vim | 4 ++++ autoload/airline/extensions/ctrlp.vim | 33 +++++++++++++++------------ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/autoload/airline/builder.vim b/autoload/airline/builder.vim index a6c867c4..c1658974 100644 --- a/autoload/airline/builder.vim +++ b/autoload/airline/builder.vim @@ -8,6 +8,10 @@ function! s:prototype.split(...) let self._line .= '%#'.self._curgroup.'#'.(a:0 ? a:1 : '%=') endfunction +function! s:prototype.add_section_spaced(group, contents) + call self.add_section(a:group, (g:airline_symbols.space).a:contents.(g:airline_symbols.space)) +endfunction + function! s:prototype.add_section(group, contents) if self._curgroup != '' if self._curgroup == a:group diff --git a/autoload/airline/extensions/ctrlp.vim b/autoload/airline/extensions/ctrlp.vim index e114ae53..64e28854 100644 --- a/autoload/airline/extensions/ctrlp.vim +++ b/autoload/airline/extensions/ctrlp.vim @@ -33,22 +33,25 @@ function! airline#extensions#ctrlp#load_theme(palette) endfor endfunction -" Arguments: focus, byfname, s:regexp, prv, item, nxt, marked +" Arguments: focus, byfname, regexp, prv, item, nxt, marked function! airline#extensions#ctrlp#ctrlp_airline(...) - let regex = a:3 ? '%#CtrlPlight# regex %*' : '' - let prv = '%#CtrlPlight# '.a:4.' %#Ctrlparrow1#'.g:airline_left_sep - let item = '%#CtrlPwhite# '.a:5.' %#CtrlParrow2#'.g:airline_left_sep - let nxt = '%#CtrlPlight# '.a:6.' %#CtrlParrow3#'.g:airline_left_sep - let marked = '%#CtrlPdark# '.a:7.(g:airline_symbols.space) - 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().' %*' - if get(g:, 'airline#extensions#ctrlp#show_adjacent_modes', 1) - let modes = prv.item.nxt - else - let modes = item + let b = airline#builder#new({'active': 1}) + if a:3 + call b.add_section_spaced('CtrlPlight', 'regex') endif - return regex.modes.marked.focus.byfname.dir + if get(g:, 'airline#extensions#ctrlp#show_adjacent_modes', 1) + call b.add_section_spaced('CtrlPlight', a:4) + call b.add_section_spaced('CtrlPwhite', a:5) + call b.add_section_spaced('CtrlPlight', a:6) + else + call b.add_section_spaced('CtrlPwhite', a:5) + endif + call b.add_section_spaced('CtrlPdark', a:7) + call b.split() + call b.add_raw('%#CtrlPdark#'.a:1.(g:airline_symbols.space)) + call b.add_section_spaced('CtrlPdark', a:2) + call b.add_section_spaced('CtrlPlight', '%{getcwd()}') + return b.build() endfunction " Argument: len @@ -60,7 +63,7 @@ endfunction function! airline#extensions#ctrlp#apply(...) " disable statusline overwrite if ctrlp already did it - return match(&statusline, 'CtrlPlight') >= 0 ? -1 : 0 + return match(&statusline, 'CtrlPwhite') >= 0 ? -1 : 0 endfunction function! airline#extensions#ctrlp#init(ext)