From e10b690cdfd3f29ca3db0e76baeced7872d9b5be Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Wed, 28 Aug 2013 23:29:35 +0000 Subject: [PATCH] convert mode/paste/iminsert parts to function names. --- autoload/airline/parts.vim | 22 ++++++++++++++++++++-- autoload/airline/util.vim | 18 ++++++++++++++++++ plugin/airline.vim | 20 ++++++++++---------- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/autoload/airline/parts.vim b/autoload/airline/parts.vim index 0c7ece9..917a469 100644 --- a/autoload/airline/parts.vim +++ b/autoload/airline/parts.vim @@ -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 diff --git a/autoload/airline/util.vim b/autoload/airline/util.vim index 3581698..e556024 100644 --- a/autoload/airline/util.vim +++ b/autoload/airline/util.vim @@ -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) diff --git a/plugin/airline.vim b/plugin/airline.vim index 0547d4d..341a8a7 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -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).'%=')