introduce parts metadata.

This commit is contained in:
Bailey Ling 2013-08-30 21:51:10 +00:00
parent a927bf9475
commit fa517238c7
6 changed files with 49 additions and 55 deletions

View File

@ -31,6 +31,6 @@ function! airline#extensions#branch#get_head()
endfunction
function! airline#extensions#branch#init(ext)
let g:airline_parts.branch = 'airline#extensions#branch#get_head'
call airline#parts#define_function('branch', 'airline#extensions#branch#get_head')
endfunction

View File

@ -14,5 +14,6 @@ function! airline#extensions#bufferline#init(ext)
let g:bufferline_separator = ' '
endif
let g:airline_parts.file = '%{bufferline#refresh_status()}'.bufferline#get_status_string()
call airline#parts#define_raw('file', '%{bufferline#refresh_status()}'.bufferline#get_status_string())
endfunction

View File

@ -54,6 +54,6 @@ function! airline#extensions#hunks#get_hunks()
endfunction
function! airline#extensions#hunks#init(ext)
let g:airline_parts.hunks = 'airline#extensions#hunks#get_hunks'
call airline#parts#define_function('hunks', 'airline#extensions#hunks#get_hunks')
endfunction

View File

@ -1,14 +1,27 @@
" 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
let s:parts = {}
function! airline#parts#define(key, config)
let s:parts[a:key] = get(s:parts, a:key, {})
call extend(s:parts[a:key], a:config)
endfunction
function! airline#parts#prepend(name)
let val = function(a:name)()
return empty(val) ? '' : val.' '.g:airline_right_alt_sep.' '
function! airline#parts#define_function(key, name)
call airline#parts#define(a:key, { 'function': a:name })
endfunction
function! airline#parts#define_text(key, text)
call airline#parts#define(a:key, { 'text': a:text })
endfunction
function! airline#parts#define_raw(key, raw)
call airline#parts#define(a:key, { 'raw': a:raw })
endfunction
function! airline#parts#get(key)
return get(s:parts, a:key, {})
endfunction
function! airline#parts#empty()

View File

@ -1,39 +1,12 @@
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
function! s:get_val(part, append)
if has_key(g:airline_parts, a:part)
let val = g:airline_parts[a:part]
if match(val, '%\| ') > -1
return val
elseif a:append > 0
return '%{airline#parts#append("'.val.'")}'
elseif a:append < 0
return '%{airline#parts#prepend("'.val.'")}'
else
return '%{'.val.'()}'
endif
endif
return a:part
function! airline#util#append(text)
return empty(a:text) ? '' : ' '.g:airline_left_alt_sep.' '.a:text
endfunction
function! airline#util#define_left_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], 0)
for i in range(1, len(a:parts) - 1)
let g:airline_section_{a:key} .= s:get_val(a:parts[i], 1)
endfor
endif
endfunction
function! airline#util#define_right_section(key, parts)
if !exists('g:airline_section_{a:key}') && len(a:parts) > 0
let g:airline_section_{a:key} = ''
for i in range(0, len(a:parts) - 2)
let g:airline_section_{a:key} .= s:get_val(a:parts[i], -1)
endfor
let g:airline_section_{a:key} .= s:get_val(a:parts[-1], 0)
endif
function! airline#util#prepend(text)
return empty(a:text) ? '' : a:text.' '.g:airline_right_alt_sep.' '
endfunction
if v:version >= 704

View File

@ -41,16 +41,18 @@ function! s:init()
\ 'branch': get(g:, 'airline_branch_prefix', get(g:, 'airline_powerline_fonts', 0) ? '' : ''),
\ }, 'keep')
call airline#parts#define_function('mode', 'airline#parts#mode')
call airline#parts#define_function('iminsert', 'airline#parts#iminsert')
call airline#parts#define_function('paste', 'airline#parts#paste')
call airline#parts#define('readonly', {
\ 'function': 'airline#parts#readonly',
\ 'highlight': 'airline_file',
\ })
call airline#parts#define_raw('file', '%f%m')
call s:check_defined('g:airline_parts', {})
call extend(g:airline_parts, {
\ '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': 'airline#parts#empty',
\ 'branch': 'airline#parts#empty',
\ 'tagbar': 'airline#parts#empty',
\ 'syntastic': 'airline#parts#empty',
\ 'whitespace': 'airline#parts#empty',
@ -80,14 +82,19 @@ function! s:init()
\ }, 'keep')
call airline#extensions#load()
call airline#util#define_left_section('a', ['mode', 'paste', 'iminsert'])
call airline#util#define_left_section('b', ['hunks', 'branch'])
call airline#util#define_left_section('c', ['%<', 'file'])
call airline#util#define_left_section('gutter', ['readonly', '%='])
call airline#util#define_right_section('x', ['tagbar', '%{&filetype}'])
call airline#util#define_right_section('y', ['ffenc'])
call airline#util#define_right_section('z', ['%3p%% %{g:airline_symbols.linenr} %3l:%3c '])
call airline#util#define_right_section('warning', ['syntastic', 'whitespace'])
if !exists('g:airline_section_a')
let g:airline_section_a = airline#section#create_left(['mode', 'paste', 'iminsert'])
endif
if !exists('g:airline_section_b')
let g:airline_section_b = airline#section#create(['hunks', 'branch'])
endif
let g:airline_section_c = airline#section#create(['%<', 'file'])
let g:airline_section_gutter = airline#section#create([' ', 'readonly', '%='])
let g:airline_section_x = airline#section#create(['tagbar', '%{&filetype}'])
let g:airline_section_y = airline#section#create(['ffenc'])
let g:airline_section_z = airline#section#create(['%3p%% %{g:airline_symbols.linenr} %3l:%3c '])
let g:airline_section_warning = airline#section#create(['syntastic', 'whitespace'])
let s:airline_theme_defined = exists('g:airline_theme')
if s:airline_theme_defined || !airline#switch_matching_theme()