mirror of
https://github.com/powerline/powerline.git
synced 2025-07-25 14:54:54 +02:00
Cache statusline contents in Python
Each window is now tagged with an UUID and this UUID is used to cache the window's statusline contents in the Python VimRenderer in order to avoid translating the statusline contents to and from a vimdict unnecessarily. Refs #11.
This commit is contained in:
parent
da6367a897
commit
0bf23adbcc
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
python import sys, vim, os
|
python import sys, vim, os
|
||||||
python sys.path.append(vim.eval('expand("<sfile>:h:h:h")'))
|
python sys.path.append(vim.eval('expand("<sfile>:h:h:h")'))
|
||||||
|
python import uuid
|
||||||
python from powerline.core import Powerline
|
python from powerline.core import Powerline
|
||||||
python pl = Powerline('vim')
|
python pl = Powerline('vim')
|
||||||
|
|
||||||
@ -24,16 +25,16 @@ function! Powerline(winnr)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:UpdateAllWindows()
|
function! s:UpdateAllWindows()
|
||||||
for w in range(1, winnr('$'))
|
for winnr in range(1, winnr('$'))
|
||||||
" getwinvar() returns empty string for undefined variables.
|
" getwinvar() returns empty string for undefined variables. Use
|
||||||
" Use has_key(getwinvar(w, ''), 'powerline') if you care about variable
|
" has_key(getwinvar(winnr, ''), 'window_id') if you care about
|
||||||
" being really defined (currently with w:powerline=='' it will throw
|
" variable being really defined (currently with w:window_id=='' it
|
||||||
" E706: variable type mismatch).
|
" will throw E706: variable type mismatch).
|
||||||
if getwinvar(w, 'powerline') is# ''
|
if getwinvar(winnr, 'window_id') is# ''
|
||||||
call setwinvar(w, 'powerline', {})
|
call setwinvar(winnr, 'window_id', s:pyeval('str(uuid.uuid4())'))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call setwinvar(w, '&statusline', '%!Powerline('. w .')')
|
call setwinvar(winnr, '&statusline', '%!Powerline('. winnr .')')
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ class VimRenderer(Renderer):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(VimRenderer, self).__init__(*args, **kwargs)
|
super(VimRenderer, self).__init__(*args, **kwargs)
|
||||||
self.hl_groups = {}
|
self.hl_groups = {}
|
||||||
|
self.window_cache = {}
|
||||||
|
|
||||||
def render(self, winnr):
|
def render(self, winnr):
|
||||||
'''Render all segments.
|
'''Render all segments.
|
||||||
@ -28,17 +29,18 @@ class VimRenderer(Renderer):
|
|||||||
used in non-current windows.
|
used in non-current windows.
|
||||||
'''
|
'''
|
||||||
current = vim_getwinvar(winnr, 'current')
|
current = vim_getwinvar(winnr, 'current')
|
||||||
|
window_id = vim_getwinvar(winnr, 'window_id')
|
||||||
|
|
||||||
winwidth = vim_winwidth(winnr)
|
winwidth = vim_winwidth(winnr)
|
||||||
|
|
||||||
if current:
|
if current:
|
||||||
mode = vim_mode()
|
mode = vim_mode()
|
||||||
contents_override = None
|
contents_override = None
|
||||||
contents_cached = {segment['key']: segment['contents'] for segment in self.segments if segment['type'] == 'function'}
|
contents_cached = {segment['key']: segment['contents'] for segment in self.segments if segment['type'] == 'function'}
|
||||||
vim_setwinvar(winnr, 'powerline', contents_cached)
|
self.window_cache[window_id] = contents_cached
|
||||||
else:
|
else:
|
||||||
mode = 'nc'
|
mode = 'nc'
|
||||||
contents_cached = vim_getwinvar(winnr, 'powerline')
|
contents_override = self.window_cache.get(window_id)
|
||||||
contents_override = {k: contents_cached[k].decode('utf-8') for k in contents_cached.keys()}
|
|
||||||
|
|
||||||
statusline = super(VimRenderer, self).render(mode, width=winwidth, contents_override=contents_override)
|
statusline = super(VimRenderer, self).render(mode, width=winwidth, contents_override=contents_override)
|
||||||
statusline = statusline.replace(self.PERCENT_PLACEHOLDER, '%%')
|
statusline = statusline.replace(self.PERCENT_PLACEHOLDER, '%%')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user