Merge pull request #1006 from ZyX-I/vim-reload-local_themes
Fix Vim extension reloading when using .add_local_theme()
This commit is contained in:
commit
14a68ef8f6
|
@ -394,7 +394,8 @@ class Powerline(object):
|
||||||
self.prev_common_config = None
|
self.prev_common_config = None
|
||||||
self.prev_ext_config = None
|
self.prev_ext_config = None
|
||||||
self.pl = None
|
self.pl = None
|
||||||
self.setup_args = None
|
self.setup_args = ()
|
||||||
|
self.setup_kwargs = {}
|
||||||
self.imported_modules = set()
|
self.imported_modules = set()
|
||||||
|
|
||||||
def create_renderer(self, load_main=False, load_colors=False, load_colorscheme=False, load_theme=False):
|
def create_renderer(self, load_main=False, load_colors=False, load_colorscheme=False, load_theme=False):
|
||||||
|
@ -748,7 +749,8 @@ class Powerline(object):
|
||||||
arguments for :py:meth:`reload` method and calls :py:meth:`do_setup`.
|
arguments for :py:meth:`reload` method and calls :py:meth:`do_setup`.
|
||||||
'''
|
'''
|
||||||
self.shutdown_event.clear()
|
self.shutdown_event.clear()
|
||||||
self.setup_args = (args, kwargs)
|
self.setup_args = args
|
||||||
|
self.setup_kwargs.update(kwargs)
|
||||||
self.do_setup(*args, **kwargs)
|
self.do_setup(*args, **kwargs)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -787,8 +789,7 @@ class Powerline(object):
|
||||||
self.shutdown(set_event=True)
|
self.shutdown(set_event=True)
|
||||||
init_args, init_kwargs = self.init_args
|
init_args, init_kwargs = self.init_args
|
||||||
powerline = PowerlineClass(*init_args, **init_kwargs)
|
powerline = PowerlineClass(*init_args, **init_kwargs)
|
||||||
setup_args, setup_kwargs = self.setup_args
|
powerline.setup(*self.setup_args, **self.setup_kwargs)
|
||||||
powerline.setup(*setup_args, **setup_kwargs)
|
|
||||||
|
|
||||||
def shutdown(self, set_event=True):
|
def shutdown(self, set_event=True):
|
||||||
'''Shut down all background threads.
|
'''Shut down all background threads.
|
||||||
|
|
|
@ -49,7 +49,7 @@ class VimPowerline(Powerline):
|
||||||
the same matcher already exists.
|
the same matcher already exists.
|
||||||
'''
|
'''
|
||||||
self.update_renderer()
|
self.update_renderer()
|
||||||
key = self.get_matcher(key)
|
matcher = self.get_matcher(key)
|
||||||
theme_config = {}
|
theme_config = {}
|
||||||
for cfg_path in self.theme_levels:
|
for cfg_path in self.theme_levels:
|
||||||
try:
|
try:
|
||||||
|
@ -60,10 +60,15 @@ class VimPowerline(Powerline):
|
||||||
mergedicts(theme_config, lvl_config)
|
mergedicts(theme_config, lvl_config)
|
||||||
mergedicts(theme_config, config)
|
mergedicts(theme_config, config)
|
||||||
try:
|
try:
|
||||||
self.renderer.add_local_theme(key, {'config': theme_config})
|
self.renderer.add_local_theme(matcher, {'config': theme_config})
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
# Hack for local themes support: when reloading modules it is not
|
||||||
|
# guaranteed that .add_local_theme will be called once again, so
|
||||||
|
# this function arguments will be saved here for calling from
|
||||||
|
# .do_setup().
|
||||||
|
self.setup_kwargs.setdefault('_local_themes', []).append((key, config))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def load_main_config(self):
|
def load_main_config(self):
|
||||||
|
@ -110,7 +115,7 @@ class VimPowerline(Powerline):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return super(VimPowerline, self).get_config_paths()
|
return super(VimPowerline, self).get_config_paths()
|
||||||
|
|
||||||
def do_setup(self, pyeval=None, pycmd=None, can_replace_pyeval=True):
|
def do_setup(self, pyeval=None, pycmd=None, can_replace_pyeval=True, _local_themes=()):
|
||||||
import __main__
|
import __main__
|
||||||
if not pyeval:
|
if not pyeval:
|
||||||
pyeval = 'pyeval' if sys.version_info < (3,) else 'py3eval'
|
pyeval = 'pyeval' if sys.version_info < (3,) else 'py3eval'
|
||||||
|
@ -162,6 +167,10 @@ class VimPowerline(Powerline):
|
||||||
vim.command(' autocmd! VimLeavePre * :{pycmd} powerline.shutdown()'.format(pycmd=pycmd))
|
vim.command(' autocmd! VimLeavePre * :{pycmd} powerline.shutdown()'.format(pycmd=pycmd))
|
||||||
vim.command('augroup END')
|
vim.command('augroup END')
|
||||||
|
|
||||||
|
# Hack for local themes support after reloading.
|
||||||
|
for args in _local_themes:
|
||||||
|
self.add_local_theme(*args)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_segment_info():
|
def get_segment_info():
|
||||||
return {}
|
return {}
|
||||||
|
|
Loading…
Reference in New Issue