mirror of
https://github.com/vim-airline/vim-airline.git
synced 2026-02-20 16:48:24 +08:00
introduce parts metadata.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user