From 88f2c863aa6a201a53797dea4ca8b31b301065e0 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Wed, 11 Jan 2012 15:47:11 +0100 Subject: [PATCH] More Umlaut fixes --- plugin/UltiSnips/Compatibility.py | 6 +++--- plugin/UltiSnips/TextObjects.py | 8 ++++---- test.py | 8 ++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/plugin/UltiSnips/Compatibility.py b/plugin/UltiSnips/Compatibility.py index 1edbb97..143e174 100644 --- a/plugin/UltiSnips/Compatibility.py +++ b/plugin/UltiSnips/Compatibility.py @@ -53,7 +53,7 @@ if sys.version_info >= (3,0): def as_unicode(s): if isinstance(s, bytes): return s.decode("utf-8") - return s + return str(s) def make_suitable_for_vim(s): return s @@ -98,9 +98,9 @@ else: return self.__cmp__(other) >= 0 def as_unicode(s): - if not isinstance(s, unicode): + if isinstance(s, str): return s.decode("utf-8") - return s + return unicode(s) def make_suitable_for_vim(s): if isinstance(s, list): diff --git a/plugin/UltiSnips/TextObjects.py b/plugin/UltiSnips/TextObjects.py index c5650c7..3fa56b2 100644 --- a/plugin/UltiSnips/TextObjects.py +++ b/plugin/UltiSnips/TextObjects.py @@ -9,7 +9,7 @@ import vim from UltiSnips.Buffer import TextBuffer from UltiSnips.Compatibility import CheapTotalOrdering -from UltiSnips.Compatibility import compatible_exec +from UltiSnips.Compatibility import compatible_exec, as_unicode from UltiSnips.Geometry import Span, Position from UltiSnips.Lexer import tokenize, EscapeCharToken, TransformationToken, \ TabStopToken, MirrorToken, PythonCodeToken, VimLCodeToken, ShellCodeToken @@ -209,7 +209,7 @@ class TextObject(CheapTotalOrdering): ############## def current_text(): def fget(self): - return str(self._current_text) + return as_unicode(self._current_text) def fset(self, text): self._current_text = TextBuffer(text) @@ -478,7 +478,7 @@ class VimLCode(TextObject): TextObject.__init__(self, parent, token) def _do_update(self): - self.current_text = str(vim.eval(self._code)) + self.current_text = as_unicode(vim.eval(self._code)) def __repr__(self): return "VimLCode(%s -> %s)" % (self._start, self._end) @@ -681,7 +681,7 @@ class PythonCode(TextObject): if self._snip._rv_changed: self.current_text = self._snip.rv else: - self.current_text = str(local_d["res"]) + self.current_text = as_unicode(local_d["res"]) def __repr__(self): return "PythonCode(%s -> %s)" % (self._start, self._end) diff --git a/test.py b/test.py index e170029..73c93f9 100755 --- a/test.py +++ b/test.py @@ -1944,6 +1944,14 @@ class Snippet_With_Umlauts_OverwriteNone(_VimTest): snippets = ('ül', 'üü ${1:world} üü ${2:hello}ßß\nüüüü') keys = 'te ül' + EX + JF + JF + "end" wanted = "te üü world üü helloßß\nüüüüend" +class Snippet_With_Umlauts_Mirrors(_VimTest): + snippets = ('ül', 'üü ${1:world} üü $1') + keys = 'te ül' + EX + "hello" + wanted = "te üü hello üü hello" +class Snippet_With_Umlauts_Python(_VimTest): + snippets = ('ül', 'üü ${1:world} üü `!p snip.rv = len(t[1])*"a"`') + keys = 'te ül' + EX + "hüüll" + wanted = "te üü hüüll üü aaaaa" class Snippet_With_DoubleQuote_List(_VimTest): snippets = _snip_quote('"')