diff --git a/README.md b/README.md index 4564533..d3e9869 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # lightline.vim -A light and configurable statusline for Vim +A light and configurable statusline/tabline for Vim https://github.com/itchyny/lightline.vim @@ -58,7 +58,7 @@ landscape is my colorscheme, which is a high-contrast cui-supported colorscheme, ## Spirit of this plugin + Minimalism. The core script is very small. -+ Configurability. You can create your own component and easily add to the statusline. ++ Configurability. You can create your own component and easily add to the statusline/tabline. + Orthogonality. Any plugin should not change the settings of another plugin. Such plugin-crossing settings should be written by users in `.vimrc`. ## Author @@ -598,7 +598,7 @@ let g:lightline = { \ 'colorscheme': 'wombat', \ 'active': { \ 'left': [ [ 'mode', 'paste' ], [ 'fugitive', 'filename' ], ['ctrlpmark'] ], - \ 'right': [[ 'lineinfo', 'syntastic' ], ['percent'], [ 'fileformat', 'fileencoding', 'filetype']] + \ 'right': [ [ 'syntastic', 'lineinfo' ], ['percent'], [ 'fileformat', 'fileencoding', 'filetype' ] ] \ }, \ 'component_function': { \ 'fugitive': 'MyFugitive', @@ -607,9 +607,14 @@ let g:lightline = { \ 'filetype': 'MyFiletype', \ 'fileencoding': 'MyFileencoding', \ 'mode': 'MyMode', - \ 'syntastic': 'SyntasticStatuslineFlag', \ 'ctrlpmark': 'CtrlPMark', \ }, + \ 'component_expand': { + \ 'syntastic': 'SyntasticStatuslineFlag', + \ }, + \ 'component_type': { + \ 'syntastic': 'error', + \ }, \ 'subseparator': { 'left': '|', 'right': '|' } \ } @@ -705,6 +710,15 @@ function! TagbarStatusFunc(current, sort, fname, ...) abort return lightline#statusline(0) endfunction +augroup AutoSyntastic + autocmd! + autocmd BufWritePost *.c,*.cpp call s:syntastic() +augroup END +function! s:syntastic() + SyntasticCheck + call lightline#update() +endfunction + let g:unite_force_overwrite_statusline = 0 let g:vimfiler_force_overwrite_statusline = 0 let g:vimshell_force_overwrite_statusline = 0 diff --git a/autoload/lightline.vim b/autoload/lightline.vim index 7960809..24b22f7 100644 --- a/autoload/lightline.vim +++ b/autoload/lightline.vim @@ -3,7 +3,7 @@ " Version: 0.0 " Author: itchyny " License: MIT License -" Last Change: 2013/08/31 19:42:33. +" Last Change: 2013/09/07 16:39:34. " ============================================================================= let s:save_cpo = &cpo @@ -27,15 +27,23 @@ endfunction function! lightline#init() let s:lightline = deepcopy(get(g:, 'lightline', {})) - let s:lightline.active = get(s:lightline, 'active', {}) + for k in ['active', 'inactive', 'tabline', 'tab', 'mode_map', 'mode_fallback', + \ 'component', 'component_visible_condition', 'component_function', 'component_expand', 'component_type', + \ 'tab_component', 'tab_component_function', 'separator', 'subseparator' ] + if !has_key(s:lightline, k) | let s:lightline[k] = {} | endif + endfor call extend(s:lightline.active, { \ 'left': [ [ 'mode', 'paste' ], [ 'readonly', 'filename', 'modified' ] ], \ 'right': [ [ 'lineinfo' ], [ 'percent' ], [ 'fileformat', 'fileencoding', 'filetype' ] ] }, 'keep') - let s:lightline.inactive = get(s:lightline, 'inactive', {}) call extend(s:lightline.inactive, { \ 'left': [ [ 'filename' ] ], \ 'right': [ [ 'lineinfo' ], [ 'percent' ] ] }, 'keep') - let s:lightline.mode_map = get(s:lightline, 'mode_map', {}) + call extend(s:lightline.tabline, { + \ 'left': [ [ 'tabs' ] ], + \ 'right': [ [ 'close' ] ] }, 'keep') + call extend(s:lightline.tab, { + \ 'active': [ 'tabnum', 'filename', 'modified' ], + \ 'inactive': [ 'tabnum', 'filename', 'modified' ] }, 'keep') call extend(s:lightline.mode_map, { \ 'n': 'NORMAL', 'i': 'INSERT', 'R': 'REPLACE', 'v': 'VISUAL', \ 'V': 'V-LINE', 'c': 'COMMAND', "\": 'V-BLOCK', 's': 'SELECT', @@ -43,25 +51,25 @@ function! lightline#init() let s:lightline._mode_ = { \ 'n': 'normal', 'i': 'insert', 'R': 'replace', 'v': 'visual', 'V': 'visual', \ 'c': 'command', "\": 'visual', 's': 'select', 'S': 'select', "\": 'select' } - let s:lightline.mode_fallback = get(s:lightline, 'mode_fallback', {}) call extend(s:lightline.mode_fallback, { 'replace': 'insert', 'select': 'visual' }) - let s:lightline.component = get(s:lightline, 'component', {}) call extend(s:lightline.component, { \ 'mode': '%{lightline#mode()}', \ 'absolutepath': '%F', 'relativepath': '%f', 'filename': '%t', 'modified': '%M', 'bufnum': '%n', \ 'paste': '%{&paste?"PASTE":""}', 'readonly': '%R', 'charvalue': '%b', 'charvaluehex': '%B', \ 'fileencoding': '%{strlen(&fenc)?&fenc:&enc}', 'fileformat': '%{&fileformat}', \ 'filetype': '%{strlen(&filetype)?&filetype:"no ft"}', 'percent': '%3p%%', 'percentwin': '%P', - \ 'lineinfo': '%3l:%-2v', 'line': '%l', 'column': '%c' }, 'keep') - let s:lightline.component_visible_condition = get(s:lightline, 'component_visible_condition', {}) + \ 'lineinfo': '%3l:%-2v', 'line': '%l', 'column': '%c', 'close': '%999X X ' }, 'keep') call extend(s:lightline.component_visible_condition, { \ 'modified': '&modified||!&modifiable', 'readonly': '&readonly', 'paste': '&paste' }, 'keep') - let s:lightline.component_function = get(s:lightline, 'component_function', {}) - let s:lightline.separator = get(s:lightline, 'separator', {}) + call extend(s:lightline.component_expand, { 'tabs': 'lightline#tabs' }, 'keep') + call extend(s:lightline.component_type, { 'tabs': 'tabsel', 'close': 'raw' }, 'keep') + call extend(s:lightline.tab_component_function, { + \ 'filename': 'lightline#tab#filename', 'modified': 'lightline#tab#modified', + \ 'readonly': 'lightline#tab#readonly', 'tabnum': 'lightline#tab#tabnum' }, 'keep') call extend(s:lightline.separator, { 'left': '', 'right': '' }, 'keep') - let s:lightline.subseparator = get(s:lightline, 'subseparator', {}) call extend(s:lightline.subseparator, { 'left': '|', 'right': '|' }, 'keep') call extend(s:lightline, { 'palette': {}, 'colorscheme': 'default' }, 'keep') + set tabline=%!lightline#tabline() endfunction function! lightline#colorscheme() @@ -81,16 +89,42 @@ function! lightline#mode() return get(s:lightline.mode_map, mode(), s:lightline.mode_map['?']) endfunction +let s:mode = '' function! lightline#link(...) let mode = get(s:lightline._mode_, a:0 ? a:1 : mode(), 'normal') - for i in range(len(s:lightline.active.left)) + if s:mode == mode | return '' | endif + let s:mode = mode + let [left, right, types] = [s:lightline.active.left, s:lightline.active.right, values(s:lightline.component_type)] + for i in range(len(left)) exec printf('hi link LightLineLeft_active_%d LightLineLeft_%s_%d', i, mode, i) exec printf('hi link LightLineLeft_active_%d_%d LightLineLeft_%s_%d_%d', i, i + 1, mode, i, i + 1) + for j in types + exec printf('hi link LightLineLeft_active_%d_%s LightLineLeft_%s_%d_%s', i, j, mode, i, j) + exec printf('hi link LightLineLeft_active_%s_%d LightLineLeft_%s_%s_%d', j, i, mode, j, i) + endfor endfor exec printf('hi link LightLineMiddle_active LightLineMiddle_%s', mode) - for i in range(len(s:lightline.active.right)) + for i in range(len(right)) exec printf('hi link LightLineRight_active_%d LightLineRight_%s_%d', i, mode, i) exec printf('hi link LightLineRight_active_%d_%d LightLineRight_%s_%d_%d', i, i + 1, mode, i, i + 1) + for j in types + exec printf('hi link LightLineRight_active_%d_%s LightLineRight_%s_%d_%s', i, j, mode, i, j) + exec printf('hi link LightLineRight_active_%s_%d LightLineRight_%s_%s_%d', j, i, mode, j, i) + endfor + endfor + for j in types + exec printf('hi link LightLineLeft_active_%s LightLineLeft_%s_%s', j, mode, j) + exec printf('hi link LightLineRight_active_%s LightLineRight_%s_%s', j, mode, j) + exec printf('hi link LightLineLeft_active_%s_%d LightLineLeft_%s_%s_%d', j, len(left), mode, j, len(left)) + exec printf('hi link LightLineLeft_active_%d_%s LightLineLeft_%s_%d_%s', len(left), j, mode, len(left), j) + exec printf('hi link LightLineRight_active_%s_%d LightLineRight_%s_%s_%d', j, len(right), mode, j, len(right)) + exec printf('hi link LightLineRight_active_%d_%s LightLineRight_%s_%d_%s', len(right), j, mode, len(right), j) + for k in types + exec printf('hi link LightLineLeft_active_%s_%s LightLineLeft_%s_%s_%s', j, k, mode, j, k) + exec printf('hi link LightLineLeft_active_%s_%s LightLineLeft_%s_%s_%s', k, j, mode, k, j) + exec printf('hi link LightLineRight_active_%s_%s LightLineRight_%s_%s_%s', j, k, mode, j, k) + exec printf('hi link LightLineRight_active_%s_%s LightLineRight_%s_%s_%s', k, j, mode, k, j) + endfor endfor return '' endfunction @@ -100,25 +134,33 @@ function! s:term(l) endfunction function! lightline#highlight() - let [c, f] = [s:lightline.palette, s:lightline.mode_fallback] + let [c, f, g] = [s:lightline.palette, s:lightline.mode_fallback, s:lightline.component_type] + if (has('win32') || has('win64')) && !has('gui_running') + for u in values(c) + for v in values(u) + for _ in v | let [_[2], _[3]] = [lightline#colortable#gui2cui(_[0], _[2]), lightline#colortable#gui2cui(_[1], _[3])] | endfor + endfor + endfor + endif let [s:lightline.llen, s:lightline.rlen] = [len(c.normal.left), len(c.normal.right)] - for mode in ['normal', 'insert', 'replace', 'visual', 'inactive', 'command', 'select'] + let [s:lightline.tab_llen, s:lightline.tab_rlen] = [len(has_key(c,'tabline') ? c.tabline.left : c.normal.left), len(has_key(c,'tabline') ? c.tabline.right : c.normal.right)] + for mode in ['normal', 'insert', 'replace', 'visual', 'inactive', 'command', 'select', 'tabline'] let d = has_key(c, mode) ? mode : has_key(f, mode) && has_key(c, f[mode]) ? f[mode] : 'normal' - let left = d == 'inactive' ? s:lightline.inactive.left : s:lightline.active.left - let right = d == 'inactive' ? s:lightline.inactive.right : s:lightline.active.right + let left = d == 'tabline' ? s:lightline.tabline.left : d == 'inactive' ? s:lightline.inactive.left : s:lightline.active.left + let right = d == 'tabline' ? s:lightline.tabline.right : d == 'inactive' ? s:lightline.inactive.right : s:lightline.active.right let l = has_key(c,d) && has_key(c[d],'left') ? c[d].left : has_key(f,d) && has_key(c,f[d]) && has_key(c[f[d]],'left') ? c[f[d]].left : c.normal.left let r = has_key(c,d) && has_key(c[d],'right') ? c[d].right : has_key(f,d) && has_key(c,f[d]) && has_key(c[f[d]],'right') ? c[f[d]].right : c.normal.right let m = has_key(c,d) && has_key(c[d],'middle') ? c[d].middle[0] : has_key(f,d) && has_key(c,f[d]) && has_key(c[f[d]],'middle') ? c[f[d]].middle[0] : c.normal.middle[0] - if (has('win32') || has('win64')) && !has('gui_running') - for _ in l | let [_[2], _[3]] = [lightline#colortable#gui2cui(_[0], _[2]), lightline#colortable#gui2cui(_[1], _[3])] | endfor - for _ in r | let [_[2], _[3]] = [lightline#colortable#gui2cui(_[0], _[2]), lightline#colortable#gui2cui(_[1], _[3])] | endfor - let [m[2], m[3]] = [lightline#colortable#gui2cui(m[0], m[2]), lightline#colortable#gui2cui(_[1], m[3])] - endif for i in range(len(left)) let [li, lj] = [i < len(l) ? l[i] : m, i + 1 < len(l) ? l[i + 1] : m] 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, i>=len(l) ? m[i+1==len(left)] : li[1], i==len(left)-1 ? m[1] : lj[1], i>=len(l) ? m[2+(i+1==len(left))] : li[3], i==len(left)-1 ? m[3] : lj[3]) + for j in values(g) + let s = has_key(c,d) && has_key(c[d],j) ? c[d][j][0] : has_key(c,'tabline') && has_key(c.tabline,j) ? c.tabline[j][0] : has_key(c.normal,j) ? c.normal[j][0] : l[0] + exec printf('hi LightLineLeft_%s_%d_%s guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, i, j, li[1], s[1], li[3], s[3], s:term(li)) + exec printf('hi LightLineLeft_%s_%s_%d guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, j, i, s[1], li[1], s[3], li[3], s:term(li)) + endfor 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 range(len(right)) @@ -126,14 +168,35 @@ function! lightline#highlight() exec printf('hi LightLineRight_%s_%d_%d guifg=%s guibg=%s ctermfg=%d ctermbg=%d', mode, \ i, i+1, i>=len(r) ? m[i+1==len(right)] : ri[1], i==len(right)-1 ? m[1] : rj[1], i>=len(r) ? m[2+(i+1==len(right))] : 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)) + for j in values(g) + let s = has_key(c,d) && has_key(c[d],j) ? c[d][j][0] : has_key(c,'tabline') && has_key(c.tabline,j) ? c.tabline[j][0] : has_key(c.normal,j) ? c.normal[j][0] : l[0] + exec printf('hi LightLineRight_%s_%d_%s guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, i, j, ri[1], s[1], ri[3], s[3], s:term(ri)) + exec printf('hi LightLineRight_%s_%s_%d guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, j, i, s[1], ri[1], s[3], ri[3], s:term(ri)) + endfor + endfor + for j in values(g) + let s = has_key(c,d) && has_key(c[d],j) ? c[d][j][0] : has_key(c,'tabline') && has_key(c.tabline,j) ? c.tabline[j][0] : has_key(c.normal,j) ? c.normal[j][0] : l[0] + exec printf('hi LightLineLeft_%s_%s guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, j, s[0], s[1], s[2], s[3], s:term(s)) + exec printf('hi LightLineRight_%s_%s guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, j, s[0], s[1], s[2], s[3], s:term(s)) + exec printf('hi LightLineLeft_%s_%s_%d guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, j, len(left), s[1], m[1], s[3], m[3], s:term(s)) + exec printf('hi LightLineLeft_%s_%d_%s guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, len(left), j, m[1], s[1], m[3], s[3], s:term(m)) + exec printf('hi LightLineRight_%s_%s_%d guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, j, len(right), s[1], m[1], s[3], m[3], s:term(s)) + exec printf('hi LightLineRight_%s_%d_%s guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, len(right), j, m[1], s[1], m[3], s[3], s:term(m)) + for k in values(g) + let t = has_key(c,d) && has_key(c[d],k) ? c[d][k][0] : has_key(c,'tabline') && has_key(c.tabline,k) ? c.tabline[k][0] : has_key(c.normal,k) ? c.normal[k][0] : l[0] + exec printf('hi LightLineLeft_%s_%s_%s guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, j, k, s[1], t[1], s[3], t[3], s:term(s)) + exec printf('hi LightLineLeft_%s_%s_%s guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, k, j, t[1], s[1], t[3], s[3], s:term(t)) + exec printf('hi LightLineRight_%s_%s_%s guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, j, k, s[1], t[1], s[3], t[3], s:term(s)) + exec printf('hi LightLineRight_%s_%s_%s guifg=%s guibg=%s ctermfg=%d ctermbg=%d %s', mode, k, j, t[1], s[1], t[3], s[3], s:term(t)) + endfor endfor endfor endfunction -function! s:subseparator(x, y, s) +function! s:subseparator(x, y, s, a, b) let [c, f, v] = [ s:lightline.component, s:lightline.component_function, s:lightline.component_visible_condition ] - return '%{('.(has_key(f,a:x)?'!!strlen(exists("*'.f[a:x].'")?'.f[a:x].'():"")':get(v,a:x,has_key(c,a:x)?"1":"0")).')*(('.join(map(copy(a:y), - \'(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."'):''}" + return '%{('.(a:a?"1":has_key(f,a:x)?'!!strlen(exists("*'.f[a:x].'")?'.f[a:x].'():"")':get(v,a:x,has_key(c,a:x)?"1":"0")).')*(('.join(map(copy(a:y), + \'(has_key(f,v:val)?"!!strlen(exists(\"*".f[v:val]."\")?".f[v:val]."():\"\")":get(v,v:val,has_key(c,v:val)?"1":"1"))'),')+(')."))?('".a:s."'):''}" endfunction function! lightline#concatenate(x, s) @@ -146,30 +209,132 @@ function! lightline#concatenate(x, s) 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' - let left = has_key(s:lightline, mode) ? s:lightline[mode].left : s:lightline.active.left - let right = has_key(s:lightline, mode) ? s:lightline[mode].right : s:lightline.active.right - for i in range(len(left)) - let _ .= printf('%%#LightLineLeft_%s_%d#', mode, i) - for j in range(len(left[i])) - let _ .= substitute('%( '.(has_key(f,left[i][j])?'%{exists("*'.f[left[i][j]].'")?'.f[left[i][j]].'():""}':get(c,left[i][j],'')).' %)', '^%( %)', '', '') - if j < len(left[i]) - 1 | let _ .= s:subseparator(left[i][j], left[i][j+1:], s:lightline.subseparator.left) | endif + return s:line(0, a:inactive) +endfunction + +function! s:expand(tabline, x, l) + let [e, t] = [ s:lightline.component_expand, s:lightline.component_type ] + let [a, c, _] = [[], [], []] + for i in range(len(a:x)) + if !len(_) || len(_[-1]) | call add(_, []) | call add(c, []) | endif + for j in range(len(a:x[i])) + if has_key(e, a:x[i][j]) + try + let r = exists('*'.e[a:x[i][j]]) ? eval(e[a:x[i][j]] . '()') : '' + if type(r) == 1 && r == '' | continue | endif + let s = type(r) == 1 ? [[], [r], []] : r + unlet r + catch + continue + endtry + if len(s[0]) + if !len(a) || type(a[-1]) != type(i) || a[-1] != i + if len(_[-1]) + call add(_, s[0]) | call add(c, repeat([1], len(s[0]))) + else + call extend(_[-1], s[0]) | call extend(c[-1], repeat([1], len(s[0]))) + endif + call add(a, i) + else + call extend(_[-1], s[0]) | call extend(c[-1], repeat([1], len(s[0]))) + endif + endif + if has_key(t, a:x[i][j]) + if len(s[1]) + if len(_[-1]) + call add(_, s[1]) | call add(c, repeat([1], len(s[1]))) + else + call extend(_[-1], s[1]) | call extend(c[-1], repeat([1], len(s[1]))) + endif + call add(a, t[a:x[i][j]]) + endif + if len(s[2]) + if len(_[-1]) && (type(a[-1]) != type(i) || a[-1] != i) + call add(_, s[2]) | call add(c, repeat([1], len(s[2]))) | call add(a, i) + else + call extend(_[-1], s[2]) | call extend(c[-1], repeat([1], len(s[2]))) + endif + endif + else + if !len(a) || type(a[-1]) != type(i) || a[-1] != i + call add(a, i) + if len(_[-1]) + call add(_, s[1]) | call add(c, repeat([1], len(s[1]))) + else + call extend(_[-1], s[1]) | call extend(c[-1], repeat([1], len(s[1]))) + endif + else + call extend(_[-1], s[1]) | call extend(c[-1], repeat([1], len(s[1]))) + endif + if len(s[2]) | call extend(_[-1], s[2]) | call extend(c[-1], repeat([1], len(s[2])))| endif + endif + 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], a:x[i][j]) | call add(c[-1], 0) + endif endfor - let _ .= printf('%%#LightLineLeft_%s_%d_%d#', mode, i, i + 1) . (i < l ? s:lightline.separator.left : len(left[i]) ? s:lightline.subseparator.left : '') + endfor + call add(a, len(a:x)) + while len(_) && !len(_[-1]) | call remove(_, -1) | call remove(c, -1) | endwhile + return [a, c, _] +endfunction + +function! s:line(tabline, inactive) + let _ = a:tabline ? '' : '%{lightline#link()}' + let [l, r] = a:tabline ? [s:lightline.tab_llen, s:lightline.tab_rlen] : [s:lightline.llen, s:lightline.rlen] + let [c, f, e, t] = [s:lightline.component, s:lightline.component_function, s:lightline.component_expand, s:lightline.component_type] + 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 [ll, lc, lt] = s:expand(a:tabline, copy(l_), l) + let r_ = has_key(s:lightline, mode) ? s:lightline[mode].right : s:lightline.active.right + let [rl, rc, rt] = s:expand(a:tabline, copy(r_), r) + for i in range(len(lt)) + let _ .= printf('%%#LightLineLeft_%s_%s#', mode, ll[i]) + for j in range(len(lt[i])) + let x = substitute('%( '.(lc[i][j] ? lt[i][j] : has_key(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'&&strlen(x)>7 ? x[3:-2] : x + if j < len(lt[i]) - 1 | let _ .= s:subseparator(lt[i][j], lt[i][j+1:], s:lightline.subseparator.left, lc[i][j], lc[i][j+1:]) | endif + endfor + let _ .= printf('%%#LightLineLeft_%s_%s_%s#', mode, ll[i], ll[i + 1]) . (i < l + len(lt) - len(l_) && ll[i] < l || type(ll[i]) != type(ll[i + 1]) || type(ll[i]) && type(ll[i + 1]) && ll[i] != ll[i + 1] ? s:lightline.separator.left : len(lt[i]) ? s:lightline.subseparator.left : '') endfor let _ .= printf('%%#LightLineMiddle_%s#%%=', mode) - for i in reverse(range(len(right))) - let _ .= printf('%%#LightLineRight_%s_%d_%d#', mode, i, i + 1) . (i < r ? s:lightline.separator.right : len(right[i]) ? s:lightline.subseparator.right : '') - let _ .= printf('%%#LightLineRight_%s_%d#', mode, i) - for j in range(len(right[i])) - if j | let _ .= s:subseparator(right[i][j], right[i][:j-1], s:lightline.subseparator.right) | endif - let _ .= substitute('%( '.(has_key(f,right[i][j])?'%{exists("*'.f[right[i][j]].'")?'.f[right[i][j]].'():""}':get(c,right[i][j],'')).' %)', '^%( %)', '', '') + for i in reverse(range(len(rt))) + let _ .= printf('%%#LightLineRight_%s_%s_%s#', mode, rl[i], rl[i + 1]) . (i < r + len(rt) - len(r_) && rl[i] < r || type(rl[i]) != type(rl[i + 1]) || type(rl[i]) && type(rl[i + 1]) && rl[i] != rl[i + 1] ? s:lightline.separator.right : len(rt[i]) ? s:lightline.subseparator.right : '') + let _ .= printf('%%#LightLineRight_%s_%s#', mode, rl[i]) + for j in range(len(rt[i])) + if j | let _ .= s:subseparator(rt[i][j], rt[i][:j-1], s:lightline.subseparator.right, rc[i][j], rc[i][j+1:]) | endif + let x = substitute('%( '.(rc[i][j] ? rt[i][j] : has_key(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'&&strlen(x)>7 ? x[3:-4] : x endfor endfor return _ endfunction +function! lightline#tabline() + return s:line(1, 0) +endfunction + +function! lightline#tabs() + let [_, t, l, x, y, z] = ['', tabpagenr(), tabpagenr('$'), [], [], []] + for i in range(1, l) + call add(i @@ -67,9 +73,23 @@ OPTIONS *lightline-option* \ 'left': [ [ 'filename' ] ], \ 'right': [ [ 'lineinfo' ], \ [ 'percent' ] ] } + let g:lightline.tabline = { + \ 'left': [ [ 'tabs' ] ], + \ 'right': [ [ 'close' ] ] } +< + g:lightline.tab *g:lightline.tab* + Dictionaries to specify the components in each tabs. + The components are gathered from either + |g:lightline.tab_component| or + |g:lightline.tab_component_function|. + The default values are: +> + let g:lightline.tab = { + \ 'active': [ 'tabnum', 'filename', 'modified' ], + \ 'inactive': [ 'tabnum', 'filename', 'modified' ] } < g:lightline.component *g:lightline.component* - Dictionary for statusline components. + Dictionary for statusline/tabline components. The default value is: > let g:lightline.component = { @@ -90,7 +110,8 @@ OPTIONS *lightline-option* \ 'percentwin': '%P', \ 'lineinfo': '%3l:%-2v', \ 'line': '%l', - \ 'column': '%c' } + \ 'column': '%c' + \ 'close': '%999X X ' } < g:lightline.component_visible_condition *g:lightline.component_visible_condition* Dictionary of boolean expressions for the components. @@ -126,16 +147,54 @@ OPTIONS *lightline-option* function! MyReadonly() return &ft !~? 'help' && &readonly ? 'RO' : '' endfunction +< + g:lightline.component_expand *g:lightline.component_expand* + Another dictionary for components. You can create a component + which has a special color. For example, error components or + warning components. The functions should return one of: + + a string + + an array of three elements: + [[ left ], [ middle ], [ right ]] + The component in this dictionary has priority over + |g:lightline.component| and |g:lightline.component_function|. + See |lightline-component-expansion| for more detail. +> + let g:lightline.component_expand = { + \ 'tabs': 'lightline#tabs' } +< + g:lightline.component_type *g:lightline.component_type* + A dictionary to specify the types for components in + |g:lightline.component_expand|. The types are used to specify + the color. Specifically, the type raw is used to specify a + component which should not be wrapped by item group: %(...%). +> + let g:lightline.component_type = { + \ 'tabs': 'tabsel', + \ 'close': 'raw' } +< + g:lightline.tab_component *g:lightline.tab_component* + A dictionary for components in one tab. + + g:lightline.tab_component_function *g:lightline.tab_component_function* + Another dictionary for components in one tab. + The default value is: +> + let g:lightline.tab_component_function = { + \ 'filename': 'lightline#tab#filename', + \ 'modified': 'lightline#tab#modified', + \ 'readonly': 'lightline#tab#readonly', + \ 'tabnum': 'lightline#tab#tabnum' } < g:lightline.colorscheme *g:lightline.colorscheme* The colorscheme for lightline.vim. Currently, wombat, solarized, powerline, jellybeans, Tomorrow, - Tomorrow_Night, and landscape are available. + Tomorrow_Night, Tomorrow_Night_Blue, Tomorrow_Night_Eighties + and landscape are available. The default value is: > let g:lightline.colorscheme = 'default' < - Note that the default colorscheme is exactly the same as + Note that the default colorscheme is exactly the same as the powerline theme. g:lightline.mode_map *g:lightline.mode_map* @@ -256,11 +315,17 @@ Exposed functions for lightline.vim. This function accepts an optional argument. It should be one of the return value of |mode()|. - lightline#highlight({inactive}) *lightline#highlight()* + lightline#highlight() *lightline#highlight()* + Set the highlight groups. + + lightline#statusline({inactive}) *lightline#statusline()* Returns |statusline| strings. If the argument is 0, it returns the statusline for active window, and the statusline for inactive window otherwise. + lightline#tabline() *lightline#tabline()* + Returns the tabline string. + 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, @@ -268,6 +333,139 @@ Exposed functions for lightline.vim. sub-separator is used. +============================================================================== +COMPONENT EXPANSION *lightline-component-expansion* +You can create components, which have specific colors. This section gives an +example using |syntastic|. + +If you want to add the |syntastic| flag to the statusline, an easy example is: +> + " Example A + let g:lightline = { + \ 'active': { + \ 'right': [ [ 'lineinfo', 'syntastic' ], + \ [ 'percent' ], + \ [ 'fileformat', 'fileencoding', 'filetype' ] ] + \ }, + \ 'component_function': { + \ 'syntastic': 'SyntasticStatuslineFlag', + \ } + \ } + let g:syntastic_mode_map = { 'mode': 'passive', + \ 'active_filetypes': ['c', 'cpp'] } +< +However, the color of the syntastic component is the same as the lineinfo +component. + +In order to change the syntastic component more outstanding, you have to use +|g:lightline.component_expand|. See the following example: +> + " Example B + let g:lightline = { + \ 'active': { + \ 'right': [ [ 'syntastic', 'lineinfo' ], + \ [ 'percent' ], + \ [ 'fileformat', 'fileencoding', 'filetype' ] ] + \ }, + \ 'component_expand': { + \ 'syntastic': 'SyntasticStatuslineFlag', + \ }, + \ 'component_type': { + \ 'syntastic': 'error', + \ } + \ } + let g:syntastic_mode_map = { 'mode': 'passive' } + augroup AutoSyntastic + autocmd! + autocmd BufWritePost *.c,*.cpp call s:syntastic() + augroup END + function! s:syntastic() + SyntasticCheck + call lightline#update() + endfunction +< +In order to understand the above codes, you firstly should know how the +colorschemes work in lightline.vim. Open the following file. + autoload/lightline/colorscheme/powerline.vim +The colorscheme is created by one dictionary: s:p (abbreviation for palette). +See the value of s:p.normal.right. +> + let s:p.normal.right = [ ['gray5', 'gray10'], + \ ['gray9', 'gray4'], + \ ['gray8', 'gray2'] ] +< +This array corresponds to the structure of g:lightline.active.right. Recall +the example A. +> + " Example A + let g:lightline.active.right = [ [ 'lineinfo', 'syntastic' ], + \ [ 'percent' ], + \ [ 'fileformat', 'fileencoding', 'filetype' ] ] +< +The colors are ([fgcolor, bgcolor): + (0) [ 'lineinfo', 'syntastic' ] --- s:p.normal.right[0] = ['gray5', 'gray10'] + (1) [ 'percent' ] --- s:p.normal.right[1] = ['gray9', 'gray4'] + (2) [ 'fileformat', 'fileencoding', 'filetype' ] --- s:p.normal.right[2] = ['gray8', 'gray2'] + + +Recall the example B. +> + " Example B + let g:lightline.active.right = [ [ 'syntastic', 'lineinfo' ], + \ [ 'percent' ], + \ [ 'fileformat', 'fileencoding', 'filetype' ] ] +< +If a component is specified in |g:lightline.component_expand|, lightline.vim +expands the components before setting to statusline/tabline. In this example, +the syntastic component is expanded using the |SyntasticStatuslineFlag| function. +This function returns a {string}. Let us call it `syntastic_flag`. +> + let syntastic_flag = SyntasticStatuslineFlag() +< +The syntastic component is now expanded, so it go up to one component group. +The type of the syntastic component is error, and the palette has error +colors, the result is: +> + " Expanded result of Example B + (error) [ 'syntastic' ] --- s:p.normal.error[0] = ['gray9', 'brightestred'] + (0) [ 'lineinfo' ] --- s:p.normal.right[0] = ['gray5', 'gray10'] + (1) [ 'percent' ] --- s:p.normal.right[1] = ['gray9', 'gray4'] + (2) [ 'fileformat', 'fileencoding', 'filetype' ] --- s:p.normal.right[2] = ['gray8', 'gray2'] +< +Thus the syntastic component has the red color. + + +Another example for |g:lightline.component_expand| is the tabs component. +Actually, the expand feature is created for the tabs component. +> + let g:lightline.tabline.left = [ [ 'tabs' ] ] + let g:lightline.component_expand = { + \ 'tabs': 'lightline#tabs' } +< +Create three tabs and select the middle tab. Then execute +> + echo lightline#tabs() + " [['%1T%{lightline#onetab(1,0)}'], + " ['%2T%{lightline#onetab(2,1)}'], + " ['%3T%{lightline#onetab(3,0)}%T']] +< +It returns an array of three elements. The expanded result is: +> + " Expanded result of tabline + (0) ['%1T%{lightline#onetab(1,0)}'] --- s:p.tabline.left[0] = ['gray9', 'gray4'] + (tabsel) ['%2T%{lightline#onetab(2,1)}'] --- s:p.tabline.tabsel[0] = ['gray9', 'gray1'] + (0) ['%3T%{lightline#onetab(3,0)}%T'] --- s:p.tabline.left[0] = ['gray9', 'gray4'] +< +If the tabline components is +> + let g:lightline.tabline.left = [ [ 'A', 'B', 'tabs', 'C', 'D' ] ] +< +then the expanded result is: +> + (0) ['A', 'B', '%1T%{lightline#onetab(1,0)}'] --- s:p.tabline.left[0] + (tabsel) ['%2T%{lightline#onetab(2,1)}'] --- s:p.tabline.tabsel[0] + (0) ['%3T%{lightline#onetab(3,0)}%T', 'C', 'D'] --- s:p.tabline.left[0] +< ============================================================================== EXAMPLES *lightline-examples* @@ -414,7 +612,7 @@ For users who uses lots of plugins: \ 'colorscheme': 'wombat', \ 'active': { \ 'left': [ [ 'mode', 'paste' ], [ 'fugitive', 'filename' ], ['ctrlpmark'] ], - \ 'right': [[ 'lineinfo', 'syntastic' ], ['percent'], [ 'fileformat', 'fileencoding', 'filetype']] + \ 'right': [ [ 'syntastic', 'lineinfo' ], ['percent'], [ 'fileformat', 'fileencoding', 'filetype' ] ] \ }, \ 'component_function': { \ 'fugitive': 'MyFugitive', @@ -423,9 +621,14 @@ For users who uses lots of plugins: \ 'filetype': 'MyFiletype', \ 'fileencoding': 'MyFileencoding', \ 'mode': 'MyMode', - \ 'syntastic': 'SyntasticStatuslineFlag', \ 'ctrlpmark': 'CtrlPMark', \ }, + \ 'component_expand': { + \ 'syntastic': 'SyntasticStatuslineFlag', + \ }, + \ 'component_type': { + \ 'syntastic': 'error', + \ }, \ 'subseparator': { 'left': '|', 'right': '|' } \ } @@ -521,6 +724,15 @@ For users who uses lots of plugins: return lightline#statusline(0) endfunction + augroup AutoSyntastic + autocmd! + autocmd BufWritePost *.c,*.cpp call s:syntastic() + augroup END + function! s:syntastic() + SyntasticCheck + call lightline#update() + endfunction + let g:unite_force_overwrite_statusline = 0 let g:vimfiler_force_overwrite_statusline = 0 let g:vimshell_force_overwrite_statusline = 0