optimize newing up the builder

This commit is contained in:
Bailey Ling 2013-08-17 16:44:53 -04:00
parent 6bda68e35c
commit 3814c21125
2 changed files with 55 additions and 57 deletions

View File

@ -48,9 +48,7 @@ function! airline#get_statusline(winnr, active)
endif endif
endif endif
let info = builder.build() return builder.build()
call setwinvar(a:winnr, 'airline_current_info', info)
return info.statusline
endfunction endfunction
function! airline#update_statusline() function! airline#update_statusline()

View File

@ -1,29 +1,25 @@
" MIT license. Copyright (c) 2013 Bailey Ling. " MIT license. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2 fdm=indent " vim: et ts=2 sts=2 sw=2
function! airline#builder#new(active, highlighter) let s:prototype = {}
let builder = {}
let builder._sections = []
let builder._active = a:active
let builder._highlighter = a:highlighter
function! builder.split(gutter) function! s:prototype.split(gutter)
call add(self._sections, ['|', a:gutter]) call add(self._sections, ['|', a:gutter])
endfunction endfunction
function! builder.add_section(group, contents) function! s:prototype.add_section(group, contents)
call add(self._sections, ['airline_'.a:group, a:contents]) call add(self._sections, ['airline_'.a:group, a:contents])
endfunction endfunction
function! builder.add_raw(text) function! s:prototype.add_raw(text)
call add(self._sections, ['_', a:text]) call add(self._sections, ['_', a:text])
endfunction endfunction
function! builder._group(group) function! s:prototype._group(group)
return self._active ? a:group : a:group.'_inactive' return self._active ? a:group : a:group.'_inactive'
endfunction endfunction
function! builder.build() function! s:prototype.build()
let line = '%{airline#check_mode()}' let line = '%{airline#check_mode()}'
let side = 0 let side = 0
let prev_group = '' let prev_group = ''
@ -53,10 +49,14 @@ function! airline#builder#new(active, highlighter)
let prev_group = section[0] let prev_group = section[0]
endfor endfor
return { return line
\ 'statusline': line,
\ }
endfunction endfunction
function! airline#builder#new(active, highlighter)
let builder = copy(s:prototype)
let builder._sections = []
let builder._active = a:active
let builder._highlighter = a:highlighter
return builder return builder
endfunction endfunction