s/component_func/component_function/, s/component_flag/component_visible_condition/ (sorry for breaking back conpatibility)

This commit is contained in:
itchyny
2013-08-23 07:35:01 +09:00
parent 8b76c73502
commit 9f7ef31d5f
3 changed files with 32 additions and 34 deletions

View File

@@ -163,7 +163,7 @@ OK, so you again edit your .vimrc.
![lightline.vim - tutorial](https://raw.github.com/itchyny/lightline.vim/master/image/tutorial/9.png)
Huh? Weird!
The component does not collapse even if it has no information!
In order to avoid this, you set expressions to component\_flag, which becomes 1 only when the corresponding components have information.
In order to avoid this, you set expressions to component\_visible\_condition, which should become 1 only when the corresponding components have information.
```vim
let g:lightline = {
\ 'colorscheme': 'wombat',
@@ -174,7 +174,7 @@ In order to avoid this, you set expressions to component\_flag, which becomes 1
\ 'readonly': '%{&filetype!="help"&& &readonly?"⭤":""}',
\ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}'
\ },
\ 'component_flag': {
\ 'component_visible_condition': {
\ 'readonly': '(&filetype!="help"&& &readonly)',
\ 'modified': '(&filetype!="help"&&(&modified||!&modifiable))'
\ },
@@ -197,7 +197,7 @@ In fact, the components can be created using functions.
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'filename', 'modified' ] ] },
\ 'component_func': {
\ 'component_function': {
\ 'readonly': 'MyReadonly',
\ 'modified': 'MyModified'
\ },
@@ -238,7 +238,7 @@ Now you may know what to do.
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'filename' ] ] },
\ 'component_func': {
\ 'component_function': {
\ 'filename': 'MyFilename',
\ 'readonly': 'MyReadonly',
\ 'modified': 'MyModified'
@@ -282,7 +282,7 @@ Of course, you can name your component as you wish.
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'my_filename' ] ] },
\ 'component_func': {
\ 'component_function': {
\ 'my_filename': 'MyFilename', ...
```
@@ -297,7 +297,7 @@ Here's my setting. I use the patched font for vim-powerline.
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ], [ 'fugitive', 'filename' ] ]
\ },
\ 'component_func': {
\ 'component_function': {
\ 'modified': 'MyModified',
\ 'readonly': 'MyReadonly',
\ 'fugitive': 'MyFugitive',

View File

@@ -3,7 +3,7 @@
" Version: 0.0
" Author: itchyny
" License: MIT License
" Last Change: 2013/08/22 23:29:52.
" Last Change: 2013/08/23 07:32:53.
" =============================================================================
let s:save_cpo = &cpo
@@ -57,13 +57,13 @@ function! lightline#init()
\ 'percent': '%3p%%',
\ 'lineinfo': '%3l:%-2v',
\ 'fugitive': '%{exists("*fugitive#head")?fugitive#head():""}' }, 'keep')
let g:lightline.component_flag = get(g:lightline, 'component_flag', {})
call extend(g:lightline.component_flag, {
let g:lightline.component_visible_condition = get(g:lightline, 'component_visible_condition', {})
call extend(g:lightline.component_visible_condition, {
\ 'modified': '(&modified||!&modifiable)',
\ 'readonly': '(&readonly)',
\ 'paste': '(&paste)',
\ 'fugitive': '(exists("*fugitive#head")&&strlen(fugitive#head()))' }, 'keep')
let g:lightline.component_func = get(g:lightline, 'component_func', {})
let g:lightline.component_function = get(g:lightline, 'component_function', {})
let g:lightline.separator = get(g:lightline, 'separator', {})
call extend(g:lightline.separator, { 'left': '', 'right': '' }, 'keep')
let g:lightline.subseparator = get(g:lightline, 'subseparator', {})
@@ -132,16 +132,14 @@ function! lightline#highlight()
let [m[2], m[3]] = [s:gui2cui(m[0], m[2]), s:gui2cui(_[1], m[3])]
endif
for i in range(len(left))
let li = i < len(l) ? l[i] : l[-1]
let lj = i + 1 < len(l) ? l[i + 1] : l[-1]
let [li, lj] = [i < len(l) ? l[i] : l[-1], i + 1 < len(l) ? l[i + 1] : l[-1]]
exec printf('hi LightLineLeft_%s_%d guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, i, li[0], li[1], li[2], li[3], s:term(li))
exec printf('hi LightLineLeft_%s_%d_%d guifg=%s guibg=%s ctermfg=%d ctermbg=%d', mode,
\ i, i + 1, li[1], i == len(left) - 1 ? m[1] : lj[1], li[3], i == len(left) - 1 ? m[3] : lj[3])
endfor
exec printf('hi LightLineMiddle_%s guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, m[0], m[1], m[2], m[3], s:term(m))
for i in reverse(range(len(right)))
let ri = i < len(r) ? r[i] : r[-1]
let rj = i + 1 < len(r) ? r[i + 1] : r[-1]
let [ri, rj] = [i < len(r) ? r[i] : r[-1], i + 1 < len(r) ? r[i + 1] : r[-1]]
exec printf('hi LightLineRight_%s_%d_%d guifg=%s guibg=%s ctermfg=%d ctermbg=%d', mode,
\ i, i + 1, ri[1], i == len(right) - 1 ? m[1] : rj[1], ri[3], i == len(right) - 1 ? m[3] : rj[3])
exec printf('hi LightLineRight_%s_%d guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, i, ri[0], ri[1], ri[2], ri[3], s:term(ri))
@@ -150,20 +148,20 @@ function! lightline#highlight()
endfunction
function! lightline#subseparator(x, y, s)
return '%{('.(has_key(g:lightline.component_func,a:x)?'!!strlen('.(g:lightline.component_func[a:x]).'())':get(g:lightline.component_flag,a:x,"1")).')*('.
\join(map(copy(a:y),'(has_key(g:lightline.component_func,v:val)?"!!strlen(".g:lightline.component_func[v:val]."())":'.
\'get(g:lightline.component_flag,v:val,has_key(g:lightline.component,v:val)?"1":"0"))'),'+').")?('".a:s."'):''}"
let [c, f, v] = [ g:lightline.component, g:lightline.component_function, g:lightline.component_visible_condition ]
return '%{('.(has_key(f,a:x)?'!!strlen('.(f[a:x]).'())':get(v,a:x,"1")).')*(('.join(map(copy(a:y),
\'(has_key(f,v:val)?"!!strlen(".f[v:val]."())":get(v,v:val,has_key(c,v:val)?"1":"0"))'),')+(')."))?('".a:s."'):''}"
endfunction
function! lightline#statusline(inactive)
let _ = ''
let [_, c, f] = [ '', g:lightline.component, g:lightline.component_function ]
let mode = a:inactive ? 'inactive' : 'active'
let left = has_key(g:lightline, mode) ? g:lightline[mode].left : g:lightline.active.left
let right = has_key(g:lightline, mode) ? g:lightline[mode].right : g:lightline.active.right
for i in range(len(left))
let _ .= printf('%%#LightLineLeft_%s_%d#', mode, i)
for j in range(len(left[i]))
let _ .= '%( '.(has_key(g:lightline.component_func,left[i][j])?'%{'.g:lightline.component_func[left[i][j]].'()}':get(g:lightline.component,left[i][j],'')).' %)'
let _ .= '%( '.(has_key(f,left[i][j])?'%{'.f[left[i][j]].'()}':get(c,left[i][j],'')).' %)'
if j < len(left[i]) - 1
let _ .= lightline#subseparator(left[i][j], left[i][j+1:], g:lightline.subseparator.left)
endif
@@ -178,7 +176,7 @@ function! lightline#statusline(inactive)
if j
let _ .= lightline#subseparator(right[i][j], right[i][:j-1], g:lightline.subseparator.right)
endif
let _ .= '%( '.(has_key(g:lightline.component_func,right[i][j])?'%{'.g:lightline.component_func[right[i][j]].'()}':get(g:lightline.component,right[i][j],'')).' %)'
let _ .= '%( '.(has_key(f,right[i][j])?'%{'.f[right[i][j]].'()}':get(c,right[i][j],'')).' %)'
endfor
endfor
return _

View File

@@ -4,7 +4,7 @@ Version: 0.0
Author: itchyny (https://github.com/itchyny)
License: MIT License
Repository: https://github.com/itchyny/lightline.vim
Last Change: 2013/08/22 22:34:41.
Last Change: 2013/08/23 07:11:18.
CONTENTS *lightline-contents*
@@ -60,23 +60,23 @@ OPTIONS *lightline-options*
\ 'lineinfo': '%3l:%-2v',
\ 'fugitive': '%{exists("*fugitive#head")?fugitive#head():""}' }
<
g:lightline.component_flag *g:lightline.component_flag*
g:lightline.component_visible_condition *g:lightline.component_visible_condition*
Dictionary of boolean expressions for the components.
Each expression corresponds to if the component have non-zero
length.
For example, the flag for paste component is:
Each expression should correspond to the condition each
component have non-zero length.
For example, the visible condition for paste component is:
>
let g:lightline.component_flag = {
let g:lightline.component_visible_condition = {
\ 'paste': '(&paste)' }
<
Users are recommended to set this option together with the
component itself.
g:lightline.component_func *g:lightline.component_func*
g:lightline.component_function *g:lightline.component_function*
Another dictionary for components. This is more convenient
because the user does not have to set both component and
component_flag. If a component set to both component and
component_func, the setting of component_func has priority.
component_visible_condition. If a component set to both component and
component_function, the setting of component_function has priority.
For example, if you want a component for read-only mark, which
disappears in help windows:
>
@@ -85,7 +85,7 @@ OPTIONS *lightline-options*
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'myreadonly', 'filename', 'modified' ] ],
\ },
\ 'component_func': {
\ 'component_function': {
\ 'myreadonly': 'MyReadonly'
\ },
\ }
@@ -134,7 +134,7 @@ nice.
\ 'component': {
\ 'lineinfo': ' %3l:%-2v',
\ },
\ 'component_func': {
\ 'component_function': {
\ 'readonly': 'MyReadonly',
\ 'fugitive': 'MyFugitive'
\ },
@@ -155,7 +155,7 @@ look nice.
\ 'component': {
\ 'lineinfo': '⭡ %3l:%-2v',
\ },
\ 'component_func': {
\ 'component_function': {
\ 'readonly': 'MyReadonly',
\ 'fugitive': 'MyFugitive'
\ },
@@ -189,7 +189,7 @@ In order to define own component:
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ], [ 'myfilename' ] ]
\ },
\ 'component_func': {
\ 'component_function': {
\ 'myfilename': 'MyFilename',
\ 'myreadonly': 'MyReadonly',
\ 'mymodified': 'MyModified',
@@ -244,7 +244,7 @@ A nice example for |vim-powerline| font users:
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ], [ 'fugitive', 'filename' ] ]
\ },
\ 'component_func': {
\ 'component_function': {
\ 'fugitive': 'MyFugitive',
\ 'filename': 'MyFilename'
\ },