Support old Vims without +multibyte

This commit is contained in:
ZyX 2014-12-09 19:56:20 +03:00
parent 5d6caaeecd
commit c79adfa602
3 changed files with 34 additions and 10 deletions

View File

@ -12,10 +12,36 @@ except ImportError:
from powerline.lib.unicode import unicode from powerline.lib.unicode import unicode
try: if (
vim_encoding = vim.eval('&encoding') hasattr(vim, 'options')
except AttributeError: and hasattr(vim, 'vvars')
vim_encoding = 'utf-8' and vim.vvars['version'] > 703
):
if sys.version_info < (3,):
def get_vim_encoding():
return vim.options['encoding'] or 'ascii'
else:
def get_vim_encoding():
return vim.options['encoding'].decode('ascii') or 'ascii'
elif hasattr(vim, 'eval'):
def get_vim_encoding():
return vim.eval('&encoding') or 'ascii'
else:
def get_vim_encoding():
return 'utf-8'
get_vim_encoding.__doc__ = (
'''Get encoding used for Vim strings
:return:
Value of ``&encoding``. If it is empty (i.e. Vim is compiled
without +multibyte) returns ``'ascii'``. When building documentation
outputs ``'utf-8'`` unconditionally.
'''
)
vim_encoding = get_vim_encoding()
python_to_vim_types = { python_to_vim_types = {

View File

@ -5,7 +5,7 @@ import sys
import vim import vim
from powerline.bindings.vim import vim_get_func, vim_getoption, environ, current_tabpage from powerline.bindings.vim import vim_get_func, vim_getoption, environ, current_tabpage, get_vim_encoding
from powerline.renderer import Renderer from powerline.renderer import Renderer
from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE
from powerline.theme import Theme from powerline.theme import Theme
@ -42,7 +42,7 @@ class VimRenderer(Renderer):
self.hl_groups = {} self.hl_groups = {}
self.prev_highlight = None self.prev_highlight = None
self.strwidth_error_name = register_strwidth_error(self.strwidth) self.strwidth_error_name = register_strwidth_error(self.strwidth)
self.encoding = vim.eval('&encoding') self.encoding = get_vim_encoding()
def shutdown(self): def shutdown(self):
self.theme.shutdown() self.theme.shutdown()

View File

@ -8,7 +8,7 @@ from itertools import count
import vim import vim
from powerline.bindings.vim import vim_get_func, vim_getvar from powerline.bindings.vim import vim_get_func, vim_getvar, get_vim_encoding
from powerline import Powerline, FailedUnicode from powerline import Powerline, FailedUnicode
from powerline.lib import mergedicts from powerline.lib import mergedicts
@ -73,9 +73,7 @@ class VimPowerline(Powerline):
self.setup_kwargs.setdefault('_local_themes', []).append((key, config)) self.setup_kwargs.setdefault('_local_themes', []).append((key, config))
return True return True
@staticmethod get_encoding = staticmethod(get_vim_encoding)
def get_encoding():
return vim.eval('&encoding')
def load_main_config(self): def load_main_config(self):
return _override_from(super(VimPowerline, self).load_main_config(), 'powerline_config_overrides') return _override_from(super(VimPowerline, self).load_main_config(), 'powerline_config_overrides')