Merge remote-tracking branch 'zyx-i/fix-356' into develop
This commit is contained in:
commit
5caeac26bf
|
@ -1,5 +1,7 @@
|
|||
# vim:fileencoding=utf-8:noet
|
||||
|
||||
import sys
|
||||
|
||||
try:
|
||||
import vim
|
||||
except ImportError:
|
||||
|
@ -15,7 +17,10 @@ try:
|
|||
def vim_get_func(f, rettype=None):
|
||||
'''Return a vim function binding.'''
|
||||
try:
|
||||
return vim.bindeval('function("' + f + '")')
|
||||
func = vim.bindeval('function("' + f + '")')
|
||||
if sys.version_info >= (3,) and rettype is str:
|
||||
return (lambda *args, **kwargs: func(*args, **kwargs).decode('utf-8', errors='replace'))
|
||||
return func
|
||||
except vim.error:
|
||||
return None
|
||||
except AttributeError:
|
||||
|
@ -47,4 +52,12 @@ except AttributeError:
|
|||
|
||||
vim_get_func = VimFunc
|
||||
|
||||
getbufvar = vim_get_func('getbufvar')
|
||||
if sys.version_info < (3,) or not hasattr(vim, 'bindeval'):
|
||||
getbufvar = vim_get_func('getbufvar')
|
||||
else:
|
||||
_getbufvar = vim_get_func('getbufvar')
|
||||
def getbufvar(*args):
|
||||
r = _getbufvar(*args)
|
||||
if type(r) is bytes:
|
||||
return r.decode('utf-8')
|
||||
return r
|
||||
|
|
|
@ -15,7 +15,8 @@ if ! has('python') && ! has('python3')
|
|||
finish
|
||||
endif
|
||||
|
||||
let s:powerline_pycmd = substitute(get(g:, 'powerline_pycmd', 'py'), '\v^(py)%[thon](3?)$', '\1\2', '')
|
||||
let s:powerline_pycmd = substitute(get(g:, 'powerline_pycmd', has('python') ? 'py' : 'py3'),
|
||||
\'\v^(py)%[thon](3?)$', '\1\2', '')
|
||||
let s:powerline_pyeval = get(g:, 'powerline_pyeval', s:powerline_pycmd.'eval')
|
||||
|
||||
let s:import_cmd = 'from powerline.vim import VimPowerline'
|
||||
|
|
|
@ -7,7 +7,7 @@ from powerline.bindings.vim import getbufvar
|
|||
|
||||
|
||||
def help(matcher_info):
|
||||
return getbufvar(matcher_info['bufnr'], '&buftype') == 'help'
|
||||
return str(getbufvar(matcher_info['bufnr'], '&buftype')) == 'help'
|
||||
|
||||
|
||||
def cmdwin(matcher_info):
|
||||
|
|
|
@ -8,11 +8,10 @@ from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE
|
|||
from powerline.theme import Theme
|
||||
|
||||
import vim
|
||||
import sys
|
||||
|
||||
|
||||
vim_mode = vim_get_func('mode')
|
||||
vim_getwinvar = vim_get_func('getwinvar')
|
||||
vim_setwinvar = vim_get_func('setwinvar')
|
||||
vim_mode = vim_get_func('mode', rettype=str)
|
||||
mode_translations = {
|
||||
chr(ord('V') - 0x40): '^V',
|
||||
chr(ord('S') - 0x40): '^S',
|
||||
|
@ -55,11 +54,16 @@ class VimRenderer(Renderer):
|
|||
return self.theme
|
||||
|
||||
if hasattr(vim, 'strwidth'):
|
||||
@staticmethod
|
||||
def strwidth(string):
|
||||
# Does not work with tabs, but neither is strwidth from default
|
||||
# renderer
|
||||
return vim.strwidth(string.encode('utf-8'))
|
||||
if sys.version_info < (3,):
|
||||
@staticmethod
|
||||
def strwidth(string):
|
||||
# Does not work with tabs, but neither is strwidth from default
|
||||
# renderer
|
||||
return vim.strwidth(string.encode('utf-8'))
|
||||
else:
|
||||
@staticmethod
|
||||
def strwidth(string):
|
||||
return vim.strwidth(string)
|
||||
|
||||
def render(self, window_id, winidx, current):
|
||||
'''Render all segments.
|
||||
|
|
|
@ -19,8 +19,8 @@ from collections import defaultdict
|
|||
|
||||
vim_funcs = {
|
||||
'virtcol': vim_get_func('virtcol', rettype=int),
|
||||
'fnamemodify': vim_get_func('fnamemodify'),
|
||||
'expand': vim_get_func('expand'),
|
||||
'fnamemodify': vim_get_func('fnamemodify', rettype=str),
|
||||
'expand': vim_get_func('expand', rettype=str),
|
||||
'bufnr': vim_get_func('bufnr', rettype=int),
|
||||
'line2byte': vim_get_func('line2byte', rettype=int),
|
||||
}
|
||||
|
|
25
tests/vim.py
25
tests/vim.py
|
@ -31,6 +31,26 @@ def _logged(func):
|
|||
return f
|
||||
|
||||
|
||||
def _construct_result(r):
|
||||
import sys
|
||||
if sys.version_info < (3,):
|
||||
return r
|
||||
else:
|
||||
if type(r) is str:
|
||||
return r.encode('utf-8')
|
||||
elif type(r) is dict or type(r) is list:
|
||||
raise NotImplementedError
|
||||
return r
|
||||
|
||||
|
||||
def _str_func(func):
|
||||
from functools import wraps
|
||||
@wraps(func)
|
||||
def f(*args, **kwargs):
|
||||
return _construct_result(func(*args, **kwargs))
|
||||
return f
|
||||
|
||||
|
||||
def _log_print():
|
||||
import sys
|
||||
for entry in _log:
|
||||
|
@ -75,6 +95,7 @@ def bindeval(expr):
|
|||
|
||||
|
||||
@_logged
|
||||
@_str_func
|
||||
def _emul_mode(*args):
|
||||
if args and args[0]:
|
||||
return _mode
|
||||
|
@ -83,6 +104,7 @@ def _emul_mode(*args):
|
|||
|
||||
|
||||
@_logged
|
||||
@_str_func
|
||||
def _emul_getbufvar(bufnr, varname):
|
||||
if varname[0] == '&':
|
||||
if bufnr not in _buf_options:
|
||||
|
@ -98,6 +120,7 @@ def _emul_getbufvar(bufnr, varname):
|
|||
|
||||
|
||||
@_logged
|
||||
@_str_func
|
||||
def _emul_getwinvar(winnr, varname):
|
||||
return _win_scopes[winnr][varname]
|
||||
|
||||
|
@ -115,6 +138,7 @@ def _emul_virtcol(expr):
|
|||
|
||||
|
||||
@_logged
|
||||
@_str_func
|
||||
def _emul_fnamemodify(path, modstring):
|
||||
import os
|
||||
_modifiers = {
|
||||
|
@ -130,6 +154,7 @@ def _emul_fnamemodify(path, modstring):
|
|||
|
||||
|
||||
@_logged
|
||||
@_str_func
|
||||
def _emul_expand(expr):
|
||||
if expr == '<abuf>':
|
||||
return _buffer()
|
||||
|
|
Loading…
Reference in New Issue