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
try:
vim_encoding = vim.eval('&encoding')
except AttributeError:
vim_encoding = 'utf-8'
if (
hasattr(vim, 'options')
and hasattr(vim, 'vvars')
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 = {

View File

@ -5,7 +5,7 @@ import sys
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.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE
from powerline.theme import Theme
@ -42,7 +42,7 @@ class VimRenderer(Renderer):
self.hl_groups = {}
self.prev_highlight = None
self.strwidth_error_name = register_strwidth_error(self.strwidth)
self.encoding = vim.eval('&encoding')
self.encoding = get_vim_encoding()
def shutdown(self):
self.theme.shutdown()

View File

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