Pass the current window as a parameter to the render method
This change simplifies the code somewhat as the BufLeave, etc. autocmds aren't required anymore.
This commit is contained in:
parent
70818341e6
commit
3a8e64b767
|
@ -20,22 +20,20 @@ else
|
||||||
endfunction
|
endfunction
|
||||||
endif
|
endif
|
||||||
|
|
||||||
function! Powerline(winnr)
|
function! Powerline(winnr, current)
|
||||||
return s:pyeval('pl.renderer.render('. a:winnr .')')
|
return s:pyeval('pl.renderer.render('. a:winnr .', '. a:current .')')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:UpdateAllWindows()
|
function! s:UpdateWindows()
|
||||||
|
if ! exists('w:window_id')
|
||||||
|
let w:window_id = s:pyeval('str(uuid.uuid4())')
|
||||||
|
endif
|
||||||
for winnr in range(1, winnr('$'))
|
for winnr in range(1, winnr('$'))
|
||||||
if getwinvar(winnr, 'window_id') is# ''
|
call setwinvar(winnr, '&statusline', '%!Powerline('. winnr .', '. (w:window_id == getwinvar(winnr, 'window_id')) .')')
|
||||||
call setwinvar(winnr, 'window_id', s:pyeval('str(uuid.uuid4())'))
|
|
||||||
endif
|
|
||||||
|
|
||||||
call setwinvar(winnr, '&statusline', '%!Powerline('. winnr .')')
|
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
augroup Powerline
|
augroup Powerline
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufEnter,BufWinEnter,WinEnter * let w:current = 1 | call s:UpdateAllWindows()
|
autocmd BufEnter,BufWinEnter,WinEnter * call s:UpdateWindows()
|
||||||
autocmd BufLeave,BufWinLeave,WinLeave * let w:current = 0
|
|
||||||
augroup END
|
augroup END
|
||||||
|
|
|
@ -21,16 +21,14 @@ class VimRenderer(Renderer):
|
||||||
self.hl_groups = {}
|
self.hl_groups = {}
|
||||||
self.window_cache = {}
|
self.window_cache = {}
|
||||||
|
|
||||||
def render(self, winnr):
|
def render(self, winnr, current):
|
||||||
'''Render all segments.
|
'''Render all segments.
|
||||||
|
|
||||||
This method handles replacing of the percent placeholder for vim
|
This method handles replacing of the percent placeholder for vim
|
||||||
statuslines, and it caches segment contents which are retrieved and
|
statuslines, and it caches segment contents which are retrieved and
|
||||||
used in non-current windows.
|
used in non-current windows.
|
||||||
'''
|
'''
|
||||||
current = vim_getwinvar(winnr, 'current')
|
|
||||||
window_id = vim_getwinvar(winnr, 'window_id')
|
window_id = vim_getwinvar(winnr, 'window_id')
|
||||||
|
|
||||||
winwidth = vim_winwidth(winnr)
|
winwidth = vim_winwidth(winnr)
|
||||||
|
|
||||||
if current:
|
if current:
|
||||||
|
|
Loading…
Reference in New Issue