convert mode/paste/iminsert parts to function names.

This commit is contained in:
Bailey Ling 2013-08-28 23:29:35 +00:00
parent 8beb275534
commit e10b690cdf
3 changed files with 48 additions and 12 deletions

View File

@ -1,13 +1,31 @@
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
function! airline#parts#append(name)
let val = function(a:name)()
return empty(val) ? '' : ' '.g:airline_left_alt_sep.' '.val
endfunction
function! airline#parts#prepend(name)
let val = function(a:name)()
return empty(val) ? '' : val.' '.g:airline_right_alt_sep
endfunction
function! airline#parts#empty()
return ''
endfunction
function! airline#parts#mode()
return get(w:, 'airline_current_mode', '')
endfunction
function! airline#parts#paste()
return g:airline_detect_paste && &paste ? ' '.g:airline_symbols.paste : ''
return g:airline_detect_paste && &paste ? g:airline_symbols.paste : ''
endfunction
function! airline#parts#iminsert()
if g:airline_detect_iminsert && &iminsert && exists('b:keymap_name')
return ' '.g:airline_left_alt_sep.' '.toupper(b:keymap_name)
return toupper(b:keymap_name)
endif
return ''
endfunction

View File

@ -1,6 +1,24 @@
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
function! s:get_val(part)
let val = g:airline_parts[a:part]
if match(val, '%') > -1
return val
else
return '%{function("'.val.'")()}'
endif
endfunction
function! airline#util#define_section(key, parts)
if !exists('g:airline_section_{a:key}') && len(a:parts) > 0
let g:airline_section_{a:key} = s:get_val(a:parts[0])
for i in range(1, len(a:parts) - 1)
let g:airline_section_{a:key} .= s:get_val(a:parts[i])
endfor
endif
endfunction
if v:version >= 704
function! airline#util#getwinvar(winnr, key, def)
return getwinvar(a:winnr, a:key, a:def)

View File

@ -34,7 +34,7 @@ function! s:init()
call s:check_defined('g:airline_symbols', {})
call extend(g:airline_symbols, {
\ 'paste': get(g:, 'airline_paste_symbol', g:airline_left_alt_sep.' PASTE'),
\ 'paste': get(g:, 'airline_paste_symbol', 'PASTE'),
\ 'readonly': get(g:, 'airline_readonly_symbol', get(g:, 'airline_powerline_fonts', 0) ? '' : 'RO'),
\ 'whitespace': get(g:, 'airline_powerline_fonts', 0) ? '✹' : '!',
\ 'linenr': get(g:, 'airline_linecolumn_prefix', get(g:, 'airline_powerline_fonts', 0) ? '' : ':' ),
@ -43,17 +43,17 @@ function! s:init()
call s:check_defined('g:airline_parts', {})
call extend(g:airline_parts, {
\ 'mode': '%{get(w:,"airline_current_mode","")}',
\ 'iminsert': '%{airline#parts#iminsert()}',
\ 'paste': '%{airline#parts#paste()}',
\ 'mode': 'airline#parts#mode',
\ 'iminsert': 'airline#parts#iminsert',
\ 'paste': 'airline#parts#paste',
\ 'readonly': '%#airline_file#%{airline#parts#readonly()}',
\ 'ffenc': '%{printf("%s%s",&fenc,strlen(&ff)>0?"[".&ff."]":"")}',
\ 'file': '%f%m',
\ 'hunks': '',
\ 'branch': '',
\ 'tagbar': '',
\ 'syntastic': '',
\ 'whitespace': '',
\ 'hunks': 'airline#parts#empty',
\ 'branch': 'airline#parts#empty',
\ 'tagbar': 'airline#parts#empty',
\ 'syntastic': 'airline#parts#empty',
\ 'whitespace': 'airline#parts#empty',
\ }, 'keep')
call s:check_defined('g:airline_mode_map', {})
@ -80,7 +80,7 @@ function! s:init()
\ }, 'keep')
call airline#extensions#load()
call s:check_defined('g:airline_section_a', (g:airline_parts.mode).(g:airline_parts.paste).(g:airline_parts.iminsert))
call airline#util#define_section('a', ['mode', 'paste', 'iminsert'])
call s:check_defined('g:airline_section_b', (g:airline_parts.hunks).(g:airline_parts.branch))
call s:check_defined('g:airline_section_c', '%<'.(g:airline_parts.file))
call s:check_defined('g:airline_section_gutter', ' '.(g:airline_parts.readonly).'%=')