mirror of
https://github.com/itchyny/lightline.vim.git
synced 2025-11-12 05:23:51 -05:00
Having raw type configuration in component_type is a kind of implementation design mistake. We sometimes want to specify both the type and the raw attribute of a component. The raw component feature shouldn't be included as one of the types of components. Now we can specify the raw attribute with component_raw and the type with component_type.
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: 2017/08/10 04:53:19.
|
" Last Change: 2017/08/21 08:19:52.
|
||||||
" =============================================================================
|
" =============================================================================
|
||||||
|
|
||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
@@ -118,6 +118,7 @@ let s:_lightline = {
|
|||||||
\ 'component_type': {
|
\ 'component_type': {
|
||||||
\ 'tabs': 'tabsel', 'close': 'raw'
|
\ 'tabs': 'tabsel', 'close': 'raw'
|
||||||
\ },
|
\ },
|
||||||
|
\ 'component_raw': {},
|
||||||
\ 'tab_component': {},
|
\ 'tab_component': {},
|
||||||
\ 'tab_component_function': {
|
\ 'tab_component_function': {
|
||||||
\ 'filename': 'lightline#tab#filename', 'modified': 'lightline#tab#modified',
|
\ 'filename': 'lightline#tab#filename', 'modified': 'lightline#tab#modified',
|
||||||
@@ -338,8 +339,9 @@ endfunction
|
|||||||
function! s:convert(name, index) abort
|
function! s:convert(name, index) abort
|
||||||
if has_key(s:lightline.component_expand, a:name)
|
if has_key(s:lightline.component_expand, a:name)
|
||||||
let type = get(s:lightline.component_type, a:name, a:index)
|
let type = get(s:lightline.component_type, a:name, a:index)
|
||||||
|
let is_raw = get(s:lightline.component_raw, a:name) || type ==# 'raw'
|
||||||
return filter(s:map(s:evaluate_expand(s:lightline.component_expand[a:name]),
|
return filter(s:map(s:evaluate_expand(s:lightline.component_expand[a:name]),
|
||||||
\ '[v:val, 1 + ' . (type ==# 'raw') . ', v:key == 1 && ' . (type !=# 'raw') . ' ? "' . type . '" : "' . a:index . '"]'), 'v:val[0] != []')
|
\ '[v:val, 1 + ' . is_raw . ', v:key == 1 && ' . (type !=# 'raw') . ' ? "' . type . '" : "' . a:index . '"]'), 'v:val[0] != []')
|
||||||
else
|
else
|
||||||
return [[[a:name], 0, a:index]]
|
return [[[a:name], 0, a:index]]
|
||||||
endif
|
endif
|
||||||
@@ -394,7 +396,7 @@ function! s:line(tabline, inactive) abort
|
|||||||
endif
|
endif
|
||||||
let [l, r] = a:tabline ? [s:lightline.tab_llen, s:lightline.tab_rlen] : [s:lightline.llen, s:lightline.rlen]
|
let [l, r] = a:tabline ? [s:lightline.tab_llen, s:lightline.tab_rlen] : [s:lightline.llen, s:lightline.rlen]
|
||||||
let [p, s] = a:tabline ? [s:lightline.tabline_separator, s:lightline.tabline_subseparator] : [s:lightline.separator, s:lightline.subseparator]
|
let [p, s] = a:tabline ? [s:lightline.tabline_separator, s:lightline.tabline_subseparator] : [s:lightline.separator, s:lightline.subseparator]
|
||||||
let [c, f, t] = [s:lightline.component, s:lightline.component_function, s:lightline.component_type]
|
let [c, f, t, w] = [s:lightline.component, s:lightline.component_function, s:lightline.component_type, s:lightline.component_raw]
|
||||||
let mode = a:tabline ? 'tabline' : a:inactive ? 'inactive' : 'active'
|
let mode = a:tabline ? 'tabline' : a:inactive ? 'inactive' : 'active'
|
||||||
let l_ = has_key(s:lightline, mode) ? s:lightline[mode].left : s:lightline.active.left
|
let l_ = has_key(s:lightline, mode) ? s:lightline[mode].left : s:lightline.active.left
|
||||||
let [lt, lc, ll] = s:expand(copy(l_))
|
let [lt, lc, ll] = s:expand(copy(l_))
|
||||||
@@ -404,7 +406,7 @@ function! s:line(tabline, inactive) abort
|
|||||||
let _ .= '%#LightlineLeft_' . mode . '_' . ll[i] . '#'
|
let _ .= '%#LightlineLeft_' . mode . '_' . ll[i] . '#'
|
||||||
for j in range(len(lt[i]))
|
for j in range(len(lt[i]))
|
||||||
let x = lc[i][j] ? lt[i][j] : has_key(f, lt[i][j]) ? (exists('*' . f[lt[i][j]]) ? '%{' . f[lt[i][j]] . '()}' : '%{exists("*' . f[lt[i][j]] . '")?' . f[lt[i][j]] . '():""}') : get(c, lt[i][j], '')
|
let x = lc[i][j] ? lt[i][j] : has_key(f, lt[i][j]) ? (exists('*' . f[lt[i][j]]) ? '%{' . f[lt[i][j]] . '()}' : '%{exists("*' . f[lt[i][j]] . '")?' . f[lt[i][j]] . '():""}') : get(c, lt[i][j], '')
|
||||||
let _ .= has_key(t, lt[i][j]) && t[lt[i][j]] ==# 'raw' || lc[i][j] ==# 2 || x ==# '' ? x : '%( ' . x . ' %)'
|
let _ .= has_key(t, lt[i][j]) && t[lt[i][j]] ==# 'raw' || get(w, lt[i][j]) || lc[i][j] ==# 2 || x ==# '' ? x : '%( ' . x . ' %)'
|
||||||
if j < len(lt[i]) - 1 && s.left !=# ''
|
if j < len(lt[i]) - 1 && s.left !=# ''
|
||||||
let _ .= s:subseparator(lt[i][(j):], s.left, lc[i][(j):])
|
let _ .= s:subseparator(lt[i][(j):], s.left, lc[i][(j):])
|
||||||
endif
|
endif
|
||||||
@@ -419,7 +421,7 @@ function! s:line(tabline, inactive) abort
|
|||||||
let _ .= '%#LightlineRight_' . mode . '_' . rl[i] . '#'
|
let _ .= '%#LightlineRight_' . mode . '_' . rl[i] . '#'
|
||||||
for j in range(len(rt[i]))
|
for j in range(len(rt[i]))
|
||||||
let x = rc[i][j] ? rt[i][j] : has_key(f, rt[i][j]) ? (exists('*' . f[rt[i][j]]) ? '%{' . f[rt[i][j]] . '()}' : '%{exists("*' . f[rt[i][j]] . '")?' . f[rt[i][j]] . '():""}') : get(c, rt[i][j], '')
|
let x = rc[i][j] ? rt[i][j] : has_key(f, rt[i][j]) ? (exists('*' . f[rt[i][j]]) ? '%{' . f[rt[i][j]] . '()}' : '%{exists("*' . f[rt[i][j]] . '")?' . f[rt[i][j]] . '():""}') : get(c, rt[i][j], '')
|
||||||
let _ .= has_key(t, rt[i][j]) && t[rt[i][j]] ==# 'raw' || rc[i][j] ==# 2 || x ==# '' ? x : '%( ' . x . ' %)'
|
let _ .= has_key(t, rt[i][j]) && t[rt[i][j]] ==# 'raw' || get(w, rt[i][j]) || rc[i][j] ==# 2 || x ==# '' ? x : '%( ' . x . ' %)'
|
||||||
if j < len(rt[i]) - 1 && s.right !=# ''
|
if j < len(rt[i]) - 1 && s.right !=# ''
|
||||||
let _ .= s:subseparator(rt[i][(j):], s.right, rc[i][(j):])
|
let _ .= s:subseparator(rt[i][(j):], s.right, rc[i][(j):])
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Version: 0.1
|
|||||||
Author: itchyny (https://github.com/itchyny)
|
Author: itchyny (https://github.com/itchyny)
|
||||||
License: MIT License
|
License: MIT License
|
||||||
Repository: https://github.com/itchyny/lightline.vim
|
Repository: https://github.com/itchyny/lightline.vim
|
||||||
Last Change: 2017/05/28 01:07:02.
|
Last Change: 2017/08/21 08:18:42.
|
||||||
|
|
||||||
CONTENTS *lightline-contents*
|
CONTENTS *lightline-contents*
|
||||||
|
|
||||||
@@ -188,11 +188,22 @@ OPTIONS *lightline-option*
|
|||||||
|g:lightline.component_expand|. The types are used to specify
|
|g:lightline.component_expand|. The types are used to specify
|
||||||
the color. Specifically, the type raw is used to specify a
|
the color. Specifically, the type raw is used to specify a
|
||||||
component which should not be wrapped by item group: %(...%).
|
component which should not be wrapped by item group: %(...%).
|
||||||
|
If you want to specify the type of a raw component, please use
|
||||||
|
|g:lightline.component_raw|.
|
||||||
The default value is: >
|
The default value is: >
|
||||||
|
|
||||||
let g:lightline.component_type = {
|
let g:lightline.component_type = {
|
||||||
\ 'tabs': 'tabsel',
|
\ 'tabs': 'tabsel',
|
||||||
\ 'close': 'raw' }
|
\ 'close': 'raw' }
|
||||||
|
<
|
||||||
|
g:lightline.component_raw *g:lightline.component_raw*
|
||||||
|
A dictionary to specify the raw type components. When you
|
||||||
|
register a component to this dictionary (like >
|
||||||
|
g:lightline.component_raw = { 'example': 1 }
|
||||||
|
< ), the example component is not wrapped by item group: %(...%).
|
||||||
|
The default value is: >
|
||||||
|
|
||||||
|
let g:lightline.component_raw = {}
|
||||||
<
|
<
|
||||||
g:lightline.tab_component *g:lightline.tab_component*
|
g:lightline.tab_component *g:lightline.tab_component*
|
||||||
A dictionary for components in one tab.
|
A dictionary for components in one tab.
|
||||||
|
|||||||
@@ -58,6 +58,19 @@ function! s:suite.raw_type()
|
|||||||
delfunction Custom
|
delfunction Custom
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:suite.component_raw()
|
||||||
|
function! Custom()
|
||||||
|
return [ ['left'], ['middle'], ['right'] ]
|
||||||
|
endfunction
|
||||||
|
let g:lightline = { 'component_expand': { 'custom': 'Custom' }, 'component_type': { 'custom': 'custom' }, 'component_raw': { 'custom': 1 } }
|
||||||
|
call lightline#init()
|
||||||
|
call s:assert.equals(s:expand([['readonly', 'filename'], ['custom'], ['modified']]),
|
||||||
|
\ [[['readonly', 'filename'], ['left'], ['middle'], ['right'], ['modified']], [[0, 0], [2], [2], [2], [0]], ['0', '1', 'custom', '1', '2', '3']])
|
||||||
|
call s:assert.equals(s:expand([['readonly', 'filename', 'custom', 'modified']]),
|
||||||
|
\ [[['readonly', 'filename', 'left'], ['middle'], ['right', 'modified']], [[0, 0, 2], [2], [2, 0]], ['0', 'custom', '0', '1']])
|
||||||
|
delfunction Custom
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:suite.multiple()
|
function! s:suite.multiple()
|
||||||
function! Custom()
|
function! Custom()
|
||||||
return [ ['x0', 'x1', 'x2'], ['y0', 'y1', 'y2'], ['z0', 'z1', 'z2'] ]
|
return [ ['x0', 'x1', 'x2'], ['y0', 'y1', 'y2'], ['z0', 'z1', 'z2'] ]
|
||||||
|
|||||||
Reference in New Issue
Block a user