Better handling of unicode in snippet definitions and names
This commit is contained in:
parent
3094d79e61
commit
cebf11eda0
@ -1,8 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
import vim
|
||||
import os
|
||||
import types
|
||||
import vim
|
||||
|
||||
def as_utf8(s):
|
||||
if not isinstance(s, types.UnicodeType):
|
||||
s = s.decode("utf-8")
|
||||
return s.encode("utf-8")
|
||||
|
||||
def vim_string(inp):
|
||||
""" Creates a vim-friendly string from a group of
|
||||
@ -10,14 +16,15 @@ def vim_string(inp):
|
||||
"""
|
||||
def conv(obj):
|
||||
if isinstance(obj, list):
|
||||
return u'[' + u",".join([conv(o) for o in obj]) + u']'
|
||||
rv = u'[' + u','.join(conv(o) for o in obj) + u']'
|
||||
elif isinstance(obj, dict):
|
||||
return u'{' + u','.join([
|
||||
rv = u'{' + u','.join([
|
||||
u"%s:%s" % (conv(key), conv(value))
|
||||
for key, value in obj.iteritems()]) + u'}'
|
||||
else:
|
||||
return u'"%s"' % str(obj).replace(u'"', u'\\"')
|
||||
return conv(inp)
|
||||
rv = u'"%s"' % str(obj).decode("utf-8").replace(u'"', u'\\"')
|
||||
return rv
|
||||
return conv(inp).encode("utf-8")
|
||||
|
||||
class IndentUtil(object):
|
||||
""" Utility class for dealing properly with indentation. """
|
||||
|
@ -14,7 +14,7 @@ import vim
|
||||
from UltiSnips.Geometry import Position
|
||||
from UltiSnips.TextObjects import *
|
||||
from UltiSnips.Buffer import VimBuffer
|
||||
from UltiSnips.Util import IndentUtil, vim_string
|
||||
from UltiSnips.Util import IndentUtil, vim_string, as_utf8
|
||||
from UltiSnips.Langmap import LangMapTranslator
|
||||
|
||||
# The following lines silence DeprecationWarnings. They are raised
|
||||
@ -266,9 +266,9 @@ class Snippet(object):
|
||||
_TABS = re.compile(r"^\t*")
|
||||
|
||||
def __init__(self, trigger, value, descr, options, globals):
|
||||
self._t = trigger
|
||||
self._v = value
|
||||
self._d = descr
|
||||
self._t = as_utf8(trigger)
|
||||
self._v = as_utf8(value)
|
||||
self._d = as_utf8(descr)
|
||||
self._opts = options
|
||||
self._matched = ""
|
||||
self._last_re = None
|
||||
|
@ -3,9 +3,13 @@
|
||||
|
||||
__all__ = [ "debug" ]
|
||||
|
||||
import types
|
||||
|
||||
def debug(s):
|
||||
if not isinstance(s, types.UnicodeType):
|
||||
s = s.decode("utf-8")
|
||||
f = open("/tmp/file.txt","a")
|
||||
f.write(s+'\n')
|
||||
f.write(s.encode("utf-8")+'\n')
|
||||
f.close()
|
||||
|
||||
|
||||
|
10
test.py
10
test.py
@ -1912,6 +1912,16 @@ class Snippet_With_DoubleQuote(_VimTest):
|
||||
keys = 'te"st' + EX
|
||||
wanted = "Expand me\"!"
|
||||
|
||||
class Snippet_With_Umlauts_List(_VimTest):
|
||||
snippets = _snip_quote(u'ü')
|
||||
keys = 'te' + LS + "2\n"
|
||||
wanted = "Expand meü!"
|
||||
|
||||
class Snippet_With_Umlauts(_VimTest):
|
||||
snippets = _snip_quote(u'ü')
|
||||
keys = u'teüst' + EX
|
||||
wanted = "Expand meü!"
|
||||
|
||||
class Snippet_With_DoubleQuote_List(_VimTest):
|
||||
snippets = _snip_quote('"')
|
||||
keys = "te" + LS + "2\n"
|
||||
|
Loading…
Reference in New Issue
Block a user