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