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
|
||||
endif
|
||||
|
||||
function! Powerline(winnr)
|
||||
return s:pyeval('pl.renderer.render('. a:winnr .')')
|
||||
function! Powerline(winnr, current)
|
||||
return s:pyeval('pl.renderer.render('. a:winnr .', '. a:current .')')
|
||||
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('$'))
|
||||
if getwinvar(winnr, 'window_id') is# ''
|
||||
call setwinvar(winnr, 'window_id', s:pyeval('str(uuid.uuid4())'))
|
||||
endif
|
||||
|
||||
call setwinvar(winnr, '&statusline', '%!Powerline('. winnr .')')
|
||||
call setwinvar(winnr, '&statusline', '%!Powerline('. winnr .', '. (w:window_id == getwinvar(winnr, 'window_id')) .')')
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
augroup Powerline
|
||||
autocmd!
|
||||
autocmd BufEnter,BufWinEnter,WinEnter * let w:current = 1 | call s:UpdateAllWindows()
|
||||
autocmd BufLeave,BufWinLeave,WinLeave * let w:current = 0
|
||||
autocmd BufEnter,BufWinEnter,WinEnter * call s:UpdateWindows()
|
||||
augroup END
|
||||
|
|
|
@ -21,16 +21,14 @@ class VimRenderer(Renderer):
|
|||
self.hl_groups = {}
|
||||
self.window_cache = {}
|
||||
|
||||
def render(self, winnr):
|
||||
def render(self, winnr, current):
|
||||
'''Render all segments.
|
||||
|
||||
This method handles replacing of the percent placeholder for vim
|
||||
statuslines, and it caches segment contents which are retrieved and
|
||||
used in non-current windows.
|
||||
'''
|
||||
current = vim_getwinvar(winnr, 'current')
|
||||
window_id = vim_getwinvar(winnr, 'window_id')
|
||||
|
||||
winwidth = vim_winwidth(winnr)
|
||||
|
||||
if current:
|
||||
|
|
Loading…
Reference in New Issue