From 320809c21147698a6892f1c859efe9703d2a1ae8 Mon Sep 17 00:00:00 2001 From: "Stephen J. Fuhry" Date: Sun, 8 Sep 2013 10:53:01 -0400 Subject: [PATCH] moving PythonToVimStr to before _catch_exception --- jedi_vim.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/jedi_vim.py b/jedi_vim.py index cf15f71..52b3ffd 100644 --- a/jedi_vim.py +++ b/jedi_vim.py @@ -34,6 +34,27 @@ class VimError(Exception): return self.message + '; created by: ' + repr(self.executing) +class PythonToVimStr(unicode): + """ Vim has a different string implementation of single quotes """ + __slots__ = [] + def __new__(cls, obj, encoding='UTF-8'): + if is_py3k or isinstance(obj, unicode): + return unicode.__new__(cls, obj) + else: + return unicode.__new__(cls, obj, encoding) + + def __repr__(self): + # this is totally stupid and makes no sense but vim/python unicode + # support is pretty bad. don't ask how I came up with this... It just + # works... + # It seems to be related to that bug: http://bugs.python.org/issue5876 + if unicode is str: + s = self + else: + s = self.encode('UTF-8') + return '"%s"' % s.replace('\\', '\\\\').replace('"', r'\"') + + def _catch_exception(string, is_eval): """ Interface between vim and python calls back to it. @@ -62,27 +83,6 @@ if not hasattr(jedi, '__version__') or jedi.__version__ < (0, 7, 0): echo_highlight('Please update your Jedi version, it is to old.') -class PythonToVimStr(unicode): - """ Vim has a different string implementation of single quotes """ - __slots__ = [] - def __new__(cls, obj, encoding='UTF-8'): - if is_py3k or isinstance(obj, unicode): - return unicode.__new__(cls, obj) - else: - return unicode.__new__(cls, obj, encoding) - - def __repr__(self): - # this is totally stupid and makes no sense but vim/python unicode - # support is pretty bad. don't ask how I came up with this... It just - # works... - # It seems to be related to that bug: http://bugs.python.org/issue5876 - if unicode is str: - s = self - else: - s = self.encode('UTF-8') - return '"%s"' % s.replace('\\', '\\\\').replace('"', r'\"') - - @catch_and_print_exceptions def get_script(source=None, column=None): jedi.settings.additional_dynamic_modules = [b.name for b in vim.buffers