Skip to content

Commit

Permalink
new function lightline#concatenate({list}, {num}) (close morhetz#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Aug 31, 2013
1 parent 3e14ff8 commit d044e87
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,8 @@ endfunction
function! CtrlPMark()
if expand('%:t') =~ 'ControlP'
call lightline#link('iR'[g:lightline.ctrlp_regex])
return g:lightline.ctrlp_prev . ' ' . g:lightline.subseparator.left . ' ' .
\ g:lightline.ctrlp_item . ' ' . g:lightline.subseparator.left . ' ' .
\ g:lightline.ctrlp_next . ' ' . g:lightline.subseparator.left . ' ' .
\ g:lightline.ctrlp_marked
return lightline#concatenate([g:lightline.ctrlp_prev, g:lightline.ctrlp_item
\ , g:lightline.ctrlp_next], 0)
else
return ''
endif
Expand All @@ -693,7 +691,6 @@ function! CtrlPStatusFunc_1(focus, byfname, regex, prev, item, next, marked)
let g:lightline.ctrlp_prev = a:prev
let g:lightline.ctrlp_item = a:item
let g:lightline.ctrlp_next = a:next
let g:lightline.ctrlp_marked = a:marked
return lightline#statusline(0)
endfunction
Expand Down
11 changes: 10 additions & 1 deletion autoload/lightline.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
" Version: 0.0
" Author: itchyny
" License: MIT License
" Last Change: 2013/08/30 01:07:12.
" Last Change: 2013/08/31 19:14:21.
" =============================================================================

let s:save_cpo = &cpo
Expand Down Expand Up @@ -136,6 +136,15 @@ function! s:subseparator(x, y, s)
\'(has_key(f,v:val)?"!!strlen(exists(\"*".f[v:val]."\")?".f[v:val]."():\"\")":get(v,v:val,has_key(c,v:val)?"1":"0"))'),')+(')."))?('".a:s."'):''}"
endfunction

function! lightline#concatenate(x, s)
let [_, k, s] = ['', 0, ' ' . [s:lightline.subseparator.left, s:lightline.subseparator.right][!!a:s] . ' ']
for i in range(len(a:x))
let [_, k] = [_ . a:x[i], k || len(a:x[i])]
if k && i + 1 < len(a:x) && len(a:x[i + 1]) | let _ .= s | endif
endfor
return _
endfunction

function! lightline#statusline(inactive)
let [_, c, f, l, r] = [ '%{lightline#link()}', s:lightline.component, s:lightline.component_function, s:lightline.llen, s:lightline.rlen ]
let mode = a:inactive ? 'inactive' : 'active'
Expand Down
20 changes: 12 additions & 8 deletions doc/lightline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/30 02:19:57.
Last Change: 2013/08/31 19:26:18.

CONTENTS *lightline-contents*

Expand Down Expand Up @@ -251,16 +251,23 @@ Exposed functions for lightline.vim.
lightline#update_once() *lightline#update_once()*
Updates the statuslines only once.

lightline#link(...) *lightline#link()*
lightline#link([mode]) *lightline#link()*
Creates links of the highlight groups for the active window.
This function accepts an optional argument. It should be one
of the return value of |mode()|.

lightline#highlight(inactive) *lightline#highlight()*
lightline#highlight({inactive}) *lightline#highlight()*
Returns |statusline| strings. If the argument is 0, it returns
the statusline for active window, and the statusline for
inactive window otherwise.

lightline#concatenate({list}, {num}) *lightline#concatenate()*
A string concatenation function. Concatenating all the strings
in {list} using the sub-separator of lightline. If {num} is 0,
then the left sub-separator is used. Otherwise, the right
sub-separator is used.


==============================================================================

EXAMPLES *lightline-examples*
Expand Down Expand Up @@ -483,10 +490,8 @@ For users who uses lots of plugins:
function! CtrlPMark()
if expand('%:t') =~ 'ControlP'
call lightline#link('iR'[g:lightline.ctrlp_regex])
return g:lightline.ctrlp_prev . ' ' . g:lightline.subseparator.left . ' ' .
\ g:lightline.ctrlp_item . ' ' . g:lightline.subseparator.left . ' ' .
\ g:lightline.ctrlp_next . ' ' . g:lightline.subseparator.left . ' ' .
\ g:lightline.ctrlp_marked
return lightline#concatenate([g:lightline.ctrlp_prev, g:lightline.ctrlp_item
\ , g:lightline.ctrlp_next], 0)
else
return ''
endif
Expand All @@ -502,7 +507,6 @@ For users who uses lots of plugins:
let g:lightline.ctrlp_prev = a:prev
let g:lightline.ctrlp_item = a:item
let g:lightline.ctrlp_next = a:next
let g:lightline.ctrlp_marked = a:marked
return lightline#statusline(0)
endfunction
Expand Down

0 comments on commit d044e87

Please sign in to comment.