From f477520ba8cd1d7743c5cf5efbd58aaf0b4d1d00 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Fri, 16 Aug 2013 01:12:02 +0000 Subject: [PATCH] move builder to its own file --- autoload/airline.vim | 57 +----------------------------------- autoload/airline/builder.vim | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 56 deletions(-) create mode 100644 autoload/airline/builder.vim diff --git a/autoload/airline.vim b/autoload/airline.vim index 77de75e3..1ce78d56 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -13,61 +13,6 @@ let s:airline_highlight_map = { \ 'file' : 'Al7', \ } -function! s:create_builder(active) - let builder = {} - let builder._sections = [] - let builder._active = a:active - - function! builder.split(gutter) - call add(self._sections, ['|', a:gutter]) - endfunction - - function! builder.add_section(group, contents) - call add(self._sections, [a:group, a:contents]) - endfunction - - function! builder.add_raw(text) - call add(self._sections, ['_', a:text]) - endfunction - - function! builder._group(group) - return '%#' . (self._active ? a:group : a:group.'_inactive') . '#' - endfunction - - function! builder.build() - let line = '%{airline#update_highlight()}' - let side = 0 - let prev_group = '' - for section in self._sections - if section[0] == '|' - let side = 1 - let line .= '%#'.prev_group.'#'.section[1] - let prev_group = '' - continue - endif - if section[0] == '_' - let line .= section[1] - continue - endif - - if prev_group != '' - let line .= side == 0 - \ ? self._group(airline#themes#exec_highlight_separator(section[0], prev_group)) - \ : self._group(airline#themes#exec_highlight_separator(prev_group, section[0])) - let line .= side == 0 - \ ? self._active ? g:airline_left_sep : g:airline_left_alt_sep - \ : self._active ? g:airline_right_sep : g:airline_right_alt_sep - endif - - let line .= self._group(section[0]).section[1] - let prev_group = section[0] - endfor - return line - endfunction - - return builder -endfunction - function! airline#exec_highlight(group, colors) let colors = a:colors if s:is_win32term @@ -126,7 +71,7 @@ function! s:get_section(winnr, key, ...) endfunction function! airline#get_statusline(winnr, active) - let builder = s:create_builder(a:active) + let builder = airline#builder#new(a:active) if s:getwinvar(a:winnr, 'airline_render_left', a:active || (!a:active && !g:airline_inactive_collapse)) call builder.add_section('Al2', s:get_section(a:winnr, 'a').'%{g:airline_detect_paste && &paste ? g:airline_paste_symbol." " : ""}') diff --git a/autoload/airline/builder.vim b/autoload/airline/builder.vim new file mode 100644 index 00000000..5b443dd5 --- /dev/null +++ b/autoload/airline/builder.vim @@ -0,0 +1,57 @@ +" MIT license. Copyright (c) 2013 Bailey Ling. +" vim: ts=2 sts=2 sw=2 fdm=indent + +function! airline#builder#new(active) + let builder = {} + let builder._sections = [] + let builder._active = a:active + + function! builder.split(gutter) + call add(self._sections, ['|', a:gutter]) + endfunction + + function! builder.add_section(group, contents) + call add(self._sections, [a:group, a:contents]) + endfunction + + function! builder.add_raw(text) + call add(self._sections, ['_', a:text]) + endfunction + + function! builder._group(group) + return '%#' . (self._active ? a:group : a:group.'_inactive') . '#' + endfunction + + function! builder.build() + let line = '%{airline#update_highlight()}' + let side = 0 + let prev_group = '' + for section in self._sections + if section[0] == '|' + let side = 1 + let line .= '%#'.prev_group.'#'.section[1] + let prev_group = '' + continue + endif + if section[0] == '_' + let line .= section[1] + continue + endif + + if prev_group != '' + let line .= side == 0 + \ ? self._group(airline#themes#exec_highlight_separator(section[0], prev_group)) + \ : self._group(airline#themes#exec_highlight_separator(prev_group, section[0])) + let line .= side == 0 + \ ? self._active ? g:airline_left_sep : g:airline_left_alt_sep + \ : self._active ? g:airline_right_sep : g:airline_right_alt_sep + endif + + let line .= self._group(section[0]).section[1] + let prev_group = section[0] + endfor + return line + endfunction + + return builder +endfunction