From dd4c90fc680a8e9b1d3d4075a5ca8c8b683fe253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20Silkeb=C3=A6kken?= Date: Thu, 13 Dec 2012 13:16:09 +0100 Subject: [PATCH] Cache and retrieve segment contents for non-current vim windows This resolves the issue with non-current windows using the contents of the currently selected window. --- examples/vim/powerline.vim | 2 +- powerline/ext/vim/renderer.py | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/examples/vim/powerline.vim b/examples/vim/powerline.vim index 33bba76a..093636e1 100644 --- a/examples/vim/powerline.vim +++ b/examples/vim/powerline.vim @@ -22,7 +22,7 @@ endfunction function! s:WinDoPowerline() if ! exists('w:powerline') - let w:powerline = '' + let w:powerline = {} endif let &l:stl = '%!Powerline('. winnr() .')' diff --git a/powerline/ext/vim/renderer.py b/powerline/ext/vim/renderer.py index 59dcadef..19ee4d59 100644 --- a/powerline/ext/vim/renderer.py +++ b/powerline/ext/vim/renderer.py @@ -21,14 +21,28 @@ class VimRenderer(Renderer): self.hl_groups = {} def render(self, winnr): + '''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') winwidth = vim_winwidth(winnr) - mode = vim_mode() - if not current: - mode = 'nc' + if current or not vim_getwinvar(winnr, 'powerline'): + contents_cached = {segment['key']: segment['contents'] for segment in self.segments if segment['type'] == 'function'} + vim_setwinvar(winnr, 'powerline', contents_cached) - statusline = super(VimRenderer, self).render(mode, winwidth) + if current: + mode = vim_mode() + contents_override = None + else: + mode = 'nc' + contents_cached = vim_getwinvar(winnr, 'powerline') + contents_override = {k: contents_cached[k].decode('utf-8') for k in contents_cached.keys()} + + statusline = super(VimRenderer, self).render(mode, winwidth, contents_override) statusline = statusline.replace(self.PERCENT_PLACEHOLDER, '%%') return statusline