Merge pull request #753 from mgedmin/fix-unicode-error-on-py3
Use vim.bindeval() to avoid Unicode problems
This commit is contained in:
commit
f66f3d8b95
16
pythonx/UltiSnips/_vim.py
Normal file → Executable file
16
pythonx/UltiSnips/_vim.py
Normal file → Executable file
@ -124,6 +124,14 @@ def eval(text):
|
||||
return rv
|
||||
|
||||
|
||||
def bindeval(text):
|
||||
"""Wraps vim.bindeval."""
|
||||
rv = vim.bindeval(as_vimencoding(text))
|
||||
if not isinstance(rv, (dict, list)):
|
||||
return as_unicode(rv)
|
||||
return rv
|
||||
|
||||
|
||||
def feedkeys(keys, mode='n'):
|
||||
"""Wrapper around vim's feedkeys function.
|
||||
|
||||
@ -242,7 +250,13 @@ def _unmap_select_mode_mapping():
|
||||
'| redir END')
|
||||
|
||||
# Check if any mappings where found
|
||||
all_maps = list(filter(len, eval(r"_tmp_smaps").splitlines()))
|
||||
if hasattr(vim, 'bindeval'):
|
||||
# Safer to use bindeval, if it exists, because it can deal with
|
||||
# non-UTF-8 characters in mappings; see GH #690.
|
||||
all_maps = bindeval(r"_tmp_smaps")
|
||||
else:
|
||||
all_maps = eval(r"_tmp_smaps")
|
||||
all_maps = list(filter(len, all_maps.splitlines()))
|
||||
if len(all_maps) == 1 and all_maps[0][0] not in ' sv':
|
||||
# "No maps found". String could be localized. Hopefully
|
||||
# it doesn't start with any of these letters in any
|
||||
|
Loading…
Reference in New Issue
Block a user