From 592cf1bf8782bd149156ecca4cdb35682dfacc59 Mon Sep 17 00:00:00 2001 From: itchyny Date: Thu, 5 Dec 2013 13:13:16 +0900 Subject: [PATCH] implement lightline#enable(), lightline#disable(), lightline#toggle() (close #49) --- autoload/lightline.vim | 47 +++++++++++++++++++++++++++++++++++++++++- doc/lightline.txt | 11 +++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/autoload/lightline.vim b/autoload/lightline.vim index d0d9ae4..7f8e395 100644 --- a/autoload/lightline.vim +++ b/autoload/lightline.vim @@ -3,7 +3,7 @@ " Version: 0.0 " Author: itchyny " License: MIT License -" Last Change: 2013/12/04 08:40:56. +" Last Change: 2013/12/05 13:11:43. " ============================================================================= let s:save_cpo = &cpo @@ -26,6 +26,49 @@ function! lightline#update_once() if !exists('w:lightline') || w:lightline | call lightline#update() | endif endfunction +function! lightline#update_disable() + if !s:lightline.enable.statusline | return | endif + call setwinvar(1, '&statusline', '') +endfunction + +function! lightline#enable() + call lightline#colorscheme() + call lightline#update() + if s:lightline.enable.tabline | set tabline=%!lightline#tabline() | endif + augroup LightLine + autocmd! + autocmd WinEnter,BufWinEnter,FileType,ColorScheme * call lightline#update() + autocmd ColorScheme,SessionLoadPost * call lightline#highlight() + autocmd CursorMoved,BufUnload * call lightline#update_once() + augroup END + augroup LightLineDisable + autocmd! + augroup END + augroup! LightLineDisable +endfunction + +function! lightline#disable() + let [&statusline, &tabline] = [get(s:, '_statusline', ''), get(s:, '_tabline', '')] + for t in range(1, tabpagenr('$')) + for n in range(1, tabpagewinnr(t, '$')) + call settabwinvar(t, n, '&statusline', '') + call settabwinvar(t, n, 'lightline', 0) + endfor + endfor + augroup LightLine + autocmd! + augroup END + augroup! LightLine + augroup LightLineDisable + autocmd! + autocmd WinEnter * call lightline#update_disable() + augroup END +endfunction + +function! lightline#toggle() + if exists('#LightLine') | call lightline#disable() | else | call lightline#enable() | endif +endfunction + function! lightline#init() let s:lightline = deepcopy(get(g:, 'lightline', {})) for k in ['active', 'inactive', 'tabline', 'tab', 'mode_map', 'mode_fallback', 'enable', @@ -73,6 +116,8 @@ function! lightline#init() call extend(s:lightline.tabline_subseparator, s:lightline.subseparator, 'keep') call extend(s:lightline, { 'palette': {}, 'colorscheme': 'default' }, 'keep') call extend(s:lightline.enable, { 'statusline': 1, 'tabline': 1 }, 'keep') + if !exists('s:_statusline') | let s:_statusline = &statusline | endif + if !exists('s:_tabline') | let s:_tabline = &tabline | endif if s:lightline.enable.tabline | set tabline=%!lightline#tabline() | endif endfunction diff --git a/doc/lightline.txt b/doc/lightline.txt index 76558cd..3b3cf4a 100644 --- a/doc/lightline.txt +++ b/doc/lightline.txt @@ -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/10/20 19:16:34. +Last Change: 2013/12/04 18:17:07. CONTENTS *lightline-contents* @@ -346,6 +346,15 @@ Exposed functions for lightline.vim. lightline#update_once() *lightline#update_once()* Updates the statuslines only once. + lightline#enable() *lightline#enable()* + Enables |lightline|. + + lightline#disable() *lightline#disable()* + Disables |lightline|. + + lightline#toggle() *lightline#toggle()* + Toggles |lightline|. + 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