introduce parts metadata.
This commit is contained in:
parent
a927bf9475
commit
fa517238c7
@ -31,6 +31,6 @@ function! airline#extensions#branch#get_head()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! airline#extensions#branch#init(ext)
|
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
|
endfunction
|
||||||
|
|
||||||
|
@ -14,5 +14,6 @@ function! airline#extensions#bufferline#init(ext)
|
|||||||
let g:bufferline_separator = ' '
|
let g:bufferline_separator = ' '
|
||||||
endif
|
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
|
endfunction
|
||||||
|
|
||||||
|
@ -54,6 +54,6 @@ function! airline#extensions#hunks#get_hunks()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! airline#extensions#hunks#init(ext)
|
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
|
endfunction
|
||||||
|
|
||||||
|
@ -1,14 +1,27 @@
|
|||||||
" MIT License. Copyright (c) 2013 Bailey Ling.
|
" MIT License. Copyright (c) 2013 Bailey Ling.
|
||||||
" vim: et ts=2 sts=2 sw=2
|
" vim: et ts=2 sts=2 sw=2
|
||||||
|
|
||||||
function! airline#parts#append(name)
|
let s:parts = {}
|
||||||
let val = function(a:name)()
|
|
||||||
return empty(val) ? '' : ' '.g:airline_left_alt_sep.' '.val
|
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
|
endfunction
|
||||||
|
|
||||||
function! airline#parts#prepend(name)
|
function! airline#parts#define_function(key, name)
|
||||||
let val = function(a:name)()
|
call airline#parts#define(a:key, { 'function': a:name })
|
||||||
return empty(val) ? '' : val.' '.g:airline_right_alt_sep.' '
|
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
|
endfunction
|
||||||
|
|
||||||
function! airline#parts#empty()
|
function! airline#parts#empty()
|
||||||
|
@ -1,39 +1,12 @@
|
|||||||
" MIT License. Copyright (c) 2013 Bailey Ling.
|
" MIT License. Copyright (c) 2013 Bailey Ling.
|
||||||
" vim: et ts=2 sts=2 sw=2
|
" vim: et ts=2 sts=2 sw=2
|
||||||
|
|
||||||
function! s:get_val(part, append)
|
function! airline#util#append(text)
|
||||||
if has_key(g:airline_parts, a:part)
|
return empty(a:text) ? '' : ' '.g:airline_left_alt_sep.' '.a:text
|
||||||
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
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! airline#util#define_left_section(key, parts)
|
function! airline#util#prepend(text)
|
||||||
if !exists('g:airline_section_{a:key}') && len(a:parts) > 0
|
return empty(a:text) ? '' : a:text.' '.g:airline_right_alt_sep.' '
|
||||||
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
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
if v:version >= 704
|
if v:version >= 704
|
||||||
|
@ -41,16 +41,18 @@ function! s:init()
|
|||||||
\ 'branch': get(g:, 'airline_branch_prefix', get(g:, 'airline_powerline_fonts', 0) ? '' : ''),
|
\ 'branch': get(g:, 'airline_branch_prefix', get(g:, 'airline_powerline_fonts', 0) ? '' : ''),
|
||||||
\ }, 'keep')
|
\ }, '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 s:check_defined('g:airline_parts', {})
|
||||||
call extend(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."]":"")}',
|
\ 'ffenc': '%{printf("%s%s",&fenc,strlen(&ff)>0?"[".&ff."]":"")}',
|
||||||
\ 'file': '%f%m',
|
|
||||||
\ 'hunks': 'airline#parts#empty',
|
|
||||||
\ 'branch': 'airline#parts#empty',
|
|
||||||
\ 'tagbar': 'airline#parts#empty',
|
\ 'tagbar': 'airline#parts#empty',
|
||||||
\ 'syntastic': 'airline#parts#empty',
|
\ 'syntastic': 'airline#parts#empty',
|
||||||
\ 'whitespace': 'airline#parts#empty',
|
\ 'whitespace': 'airline#parts#empty',
|
||||||
@ -80,14 +82,19 @@ function! s:init()
|
|||||||
\ }, 'keep')
|
\ }, 'keep')
|
||||||
|
|
||||||
call airline#extensions#load()
|
call airline#extensions#load()
|
||||||
call airline#util#define_left_section('a', ['mode', 'paste', 'iminsert'])
|
|
||||||
call airline#util#define_left_section('b', ['hunks', 'branch'])
|
if !exists('g:airline_section_a')
|
||||||
call airline#util#define_left_section('c', ['%<', 'file'])
|
let g:airline_section_a = airline#section#create_left(['mode', 'paste', 'iminsert'])
|
||||||
call airline#util#define_left_section('gutter', ['readonly', '%='])
|
endif
|
||||||
call airline#util#define_right_section('x', ['tagbar', '%{&filetype}'])
|
if !exists('g:airline_section_b')
|
||||||
call airline#util#define_right_section('y', ['ffenc'])
|
let g:airline_section_b = airline#section#create(['hunks', 'branch'])
|
||||||
call airline#util#define_right_section('z', ['%3p%% %{g:airline_symbols.linenr} %3l:%3c '])
|
endif
|
||||||
call airline#util#define_right_section('warning', ['syntastic', 'whitespace'])
|
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')
|
let s:airline_theme_defined = exists('g:airline_theme')
|
||||||
if s:airline_theme_defined || !airline#switch_matching_theme()
|
if s:airline_theme_defined || !airline#switch_matching_theme()
|
||||||
|
Loading…
Reference in New Issue
Block a user