mirror of
https://github.com/itchyny/lightline.vim.git
synced 2025-11-14 14:33:51 -05:00
refactor s:expand
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
" Filename: autoload/lightline.vim
|
" Filename: autoload/lightline.vim
|
||||||
" Author: itchyny
|
" Author: itchyny
|
||||||
" License: MIT License
|
" License: MIT License
|
||||||
" Last Change: 2016/03/21 17:50:47.
|
" Last Change: 2016/03/22 09:07:32.
|
||||||
" =============================================================================
|
" =============================================================================
|
||||||
|
|
||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
@@ -384,68 +384,43 @@ function! s:evaluate_expand(component) abort
|
|||||||
return map(type(result) == 3 ? (result + [[], [], []])[:2] : [[], [result], []], 'filter(s:normalize(v:val), "v:val !=# ''''")')
|
return map(type(result) == 3 ? (result + [[], [], []])[:2] : [[], [result], []], 'filter(s:normalize(v:val), "v:val !=# ''''")')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:_expand(a, c, _, component, type, i) abort
|
function! s:convert(name, index) abort
|
||||||
let results = s:evaluate_expand(a:component)
|
if has_key(s:lightline.component_expand, a:name)
|
||||||
if results == []
|
let type = get(s:lightline.component_type, a:name, a:index)
|
||||||
return
|
return filter(map(s:evaluate_expand(s:lightline.component_expand[a:name]), '[v:val, 1, v:key == 1 ? type : a:index]'), 'v:val[0] != []')
|
||||||
endif
|
|
||||||
for k in [0, 1, 2]
|
|
||||||
let sk = results[k]
|
|
||||||
if len(sk)
|
|
||||||
unlet! m
|
|
||||||
let m = k == 1 ? a:type : a:i
|
|
||||||
if !len(a:a) || type(a:a[-1]) != type(m) || a:a[-1] != m
|
|
||||||
if len(a:_[-1])
|
|
||||||
call add(a:_, sk)
|
|
||||||
call add(a:c, repeat([1], len(sk)))
|
|
||||||
else
|
else
|
||||||
call extend(a:_[-1], sk)
|
return [[[a:name], 0, a:index]]
|
||||||
call extend(a:c[-1], repeat([1], len(sk)))
|
|
||||||
endif
|
endif
|
||||||
call add(a:a, m)
|
|
||||||
else
|
|
||||||
if len(a:_) > 1 && !len(a:_[-1])
|
|
||||||
call remove(a:_, -1)
|
|
||||||
call remove(a:c, -1)
|
|
||||||
endif
|
|
||||||
call extend(a:_[-1], sk)
|
|
||||||
call extend(a:c[-1], repeat([1], len(sk)))
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:expand(x) abort
|
function! s:flatten(xss) abort
|
||||||
let component_expand = s:lightline.component_expand
|
let ys = []
|
||||||
let component_type = s:lightline.component_type
|
for xs in a:xss
|
||||||
let [a, c, _] = [[], [], []]
|
let ys += xs
|
||||||
for i in range(len(a:x))
|
|
||||||
if !len(_) || len(_[-1])
|
|
||||||
call add(_, [])
|
|
||||||
call add(c, [])
|
|
||||||
endif
|
|
||||||
for name in a:x[i]
|
|
||||||
if has_key(component_expand, name)
|
|
||||||
call s:_expand(a, c, _, component_expand[name], get(component_type, name, i), i)
|
|
||||||
else
|
|
||||||
if !len(a) || type(a[-1]) != type(i) || a[-1] != i
|
|
||||||
call add(a, i)
|
|
||||||
if len(_) && len(_[-1])
|
|
||||||
call add(_, [])
|
|
||||||
call add(c, [])
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
call add(_[-1], name)
|
|
||||||
call add(c[-1], 0)
|
|
||||||
endif
|
|
||||||
endfor
|
endfor
|
||||||
|
return ys
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:expand(components) abort
|
||||||
|
let components = []
|
||||||
|
let expanded = []
|
||||||
|
let indices = []
|
||||||
|
let previndex = -1
|
||||||
|
let xs = s:flatten(s:flatten(map(deepcopy(a:components), 'map(v:val, "s:convert(v:val, " . v:key . ")")')))
|
||||||
|
for [component, expand, index] in xs
|
||||||
|
if type(previndex) != type(index) || previndex != index
|
||||||
|
call add(indices, index)
|
||||||
|
call add(components, [])
|
||||||
|
call add(expanded, [])
|
||||||
|
endif
|
||||||
|
call extend(components[-1], component)
|
||||||
|
call extend(expanded[-1], repeat([expand], len(component)))
|
||||||
|
unlet previndex
|
||||||
|
let previndex = index
|
||||||
|
unlet index
|
||||||
endfor
|
endfor
|
||||||
call add(a, len(a:x))
|
call add(indices, len(a:components))
|
||||||
while len(_) && !len(_[-1])
|
return [components, expanded, indices]
|
||||||
call remove(_, -1)
|
|
||||||
call remove(c, -1)
|
|
||||||
endwhile
|
|
||||||
return [_, c, a]
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:line(tabline, inactive) abort
|
function! s:line(tabline, inactive) abort
|
||||||
|
|||||||
Reference in New Issue
Block a user