22/339 tests are failing
This commit is contained in:
parent
1653eb89ea
commit
d72eb587f6
@ -1,10 +1,11 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
|
from UltiSnips.Util import CheapTotalOrdering
|
||||||
|
|
||||||
__all__ = [ "Position", "Span" ]
|
__all__ = [ "Position", "Span" ]
|
||||||
|
|
||||||
|
class Position(CheapTotalOrdering):
|
||||||
class Position(object):
|
|
||||||
def __init__(self, line, col):
|
def __init__(self, line, col):
|
||||||
self.line = line
|
self.line = line
|
||||||
self.col = col
|
self.col = col
|
||||||
@ -43,7 +44,9 @@ class Position(object):
|
|||||||
def __cmp__(self, other):
|
def __cmp__(self, other):
|
||||||
s = self._line, self._col
|
s = self._line, self._col
|
||||||
o = other._line, other._col
|
o = other._line, other._col
|
||||||
return cmp(s,o)
|
if s < o: return -1
|
||||||
|
if s > o: return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "(%i,%i)" % (self._line, self._col)
|
return "(%i,%i)" % (self._line, self._col)
|
||||||
|
@ -9,7 +9,7 @@ into Logical Units called Tokens.
|
|||||||
import string
|
import string
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .Geometry import Position
|
from UltiSnips.Geometry import Position
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"tokenize", "EscapeCharToken", "TransformationToken", "TabStopToken",
|
"tokenize", "EscapeCharToken", "TransformationToken", "TabStopToken",
|
||||||
@ -122,7 +122,7 @@ class TabStopToken(Token):
|
|||||||
|
|
||||||
self.no = _parse_number(stream)
|
self.no = _parse_number(stream)
|
||||||
|
|
||||||
if stream.peek() is ":":
|
if stream.peek() == ":":
|
||||||
stream.next()
|
stream.next()
|
||||||
self.initial_text = _parse_till_closing_brace(stream)
|
self.initial_text = _parse_till_closing_brace(stream)
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import stat
|
|||||||
import tempfile
|
import tempfile
|
||||||
import vim
|
import vim
|
||||||
|
|
||||||
from UltiSnips.Util import IndentUtil
|
from UltiSnips.Util import IndentUtil, CheapTotalOrdering
|
||||||
from UltiSnips.Buffer import TextBuffer
|
from UltiSnips.Buffer import TextBuffer
|
||||||
from UltiSnips.Geometry import Span, Position
|
from UltiSnips.Geometry import Span, Position
|
||||||
from UltiSnips.Lexer import tokenize, EscapeCharToken, TransformationToken, \
|
from UltiSnips.Lexer import tokenize, EscapeCharToken, TransformationToken, \
|
||||||
@ -95,6 +95,7 @@ class _CleverReplace(object):
|
|||||||
|
|
||||||
def _unescape(self, v):
|
def _unescape(self, v):
|
||||||
return self._UNESCAPE.subn(lambda m: m.group(0)[-1], v)[0]
|
return self._UNESCAPE.subn(lambda m: m.group(0)[-1], v)[0]
|
||||||
|
|
||||||
def replace(self, match):
|
def replace(self, match):
|
||||||
start, end = match.span()
|
start, end = match.span()
|
||||||
|
|
||||||
@ -108,7 +109,9 @@ class _CleverReplace(object):
|
|||||||
tv = self._LONG_CASEFOLDINGS.subn(self._lcase_folding, tv)[0]
|
tv = self._LONG_CASEFOLDINGS.subn(self._lcase_folding, tv)[0]
|
||||||
tv = self._replace_conditional(match, tv)
|
tv = self._replace_conditional(match, tv)
|
||||||
|
|
||||||
return self._unescape(tv.decode("string-escape"))
|
tv = tv.replace(r'\"', '"')
|
||||||
|
tv = tv.replace(r"\'", "'")
|
||||||
|
return self._unescape(tv)
|
||||||
|
|
||||||
class _TOParser(object):
|
class _TOParser(object):
|
||||||
def __init__(self, parent_to, text, indent):
|
def __init__(self, parent_to, text, indent):
|
||||||
@ -167,12 +170,10 @@ class _TOParser(object):
|
|||||||
elif isinstance(token, VimLCodeToken):
|
elif isinstance(token, VimLCodeToken):
|
||||||
VimLCode(self._parent_to, token)
|
VimLCode(self._parent_to, token)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Public classes #
|
# Public classes #
|
||||||
###########################################################################
|
###########################################################################
|
||||||
class TextObject(object):
|
class TextObject(CheapTotalOrdering):
|
||||||
"""
|
"""
|
||||||
This base class represents any object in the text
|
This base class represents any object in the text
|
||||||
that has a span in any ways
|
that has a span in any ways
|
||||||
@ -198,7 +199,7 @@ class TextObject(object):
|
|||||||
self._cts = 0
|
self._cts = 0
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __cmp__(self, other):
|
||||||
return cmp(self._start, other._start)
|
return self._start.__cmp__(other._start)
|
||||||
|
|
||||||
##############
|
##############
|
||||||
# PROPERTIES #
|
# PROPERTIES #
|
||||||
@ -446,7 +447,7 @@ class ShellCode(TextObject):
|
|||||||
|
|
||||||
# Write the code to a temporary file
|
# Write the code to a temporary file
|
||||||
handle, path = tempfile.mkstemp(text=True)
|
handle, path = tempfile.mkstemp(text=True)
|
||||||
os.write(handle, code)
|
os.write(handle, code.encode("utf-8"))
|
||||||
os.close(handle)
|
os.close(handle)
|
||||||
|
|
||||||
os.chmod(path, stat.S_IRWXU)
|
os.chmod(path, stat.S_IRWXU)
|
||||||
@ -644,7 +645,7 @@ class PythonCode(TextObject):
|
|||||||
|
|
||||||
self._globals = {}
|
self._globals = {}
|
||||||
globals = snippet.globals.get("!p", [])
|
globals = snippet.globals.get("!p", [])
|
||||||
exec("\n".join(globals).replace("\r\n", "\n") in self._globals)
|
exec("\n".join(globals).replace("\r\n", "\n"), self._globals)
|
||||||
|
|
||||||
# Add Some convenience to the code
|
# Add Some convenience to the code
|
||||||
self._code = "import re, os, vim, string, random\n" + code
|
self._code = "import re, os, vim, string, random\n" + code
|
||||||
@ -672,7 +673,7 @@ class PythonCode(TextObject):
|
|||||||
})
|
})
|
||||||
|
|
||||||
self._code = self._code.replace("\r\n", "\n")
|
self._code = self._code.replace("\r\n", "\n")
|
||||||
exec(self._code in self._globals, local_d)
|
exec(self._code, self._globals, local_d)
|
||||||
|
|
||||||
if self._snip._rv_changed:
|
if self._snip._rv_changed:
|
||||||
self.current_text = self._snip.rv
|
self.current_text = self._snip.rv
|
||||||
|
@ -6,6 +6,22 @@ import types
|
|||||||
import vim
|
import vim
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
class CheapTotalOrdering:
|
||||||
|
"""Total ordering only appears in python 2.7. We try to stay compatible with
|
||||||
|
python 2.5 for now, so we define our own"""
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return self.__cmp__(other) < 0
|
||||||
|
|
||||||
|
def __le__(self, other):
|
||||||
|
return self.__cmp__(other) <= 0
|
||||||
|
|
||||||
|
def __gt__(self, other):
|
||||||
|
return self.__cmp__(other) > 0
|
||||||
|
|
||||||
|
def __ge__(self, other):
|
||||||
|
return self.__cmp__(other) >= 0
|
||||||
|
|
||||||
if sys.version_info > (2,8):
|
if sys.version_info > (2,8):
|
||||||
def as_utf8(s):
|
def as_utf8(s):
|
||||||
return s.encode("utf-8")
|
return s.encode("utf-8")
|
||||||
|
@ -295,7 +295,7 @@ class Snippet(object):
|
|||||||
return before.strip()
|
return before.strip()
|
||||||
else:
|
else:
|
||||||
before_words = before
|
before_words = before
|
||||||
for i in xrange(-1, -(num_words + 1), -1):
|
for i in range(-1, -(num_words + 1), -1):
|
||||||
left = before_words.rfind(word_list[i])
|
left = before_words.rfind(word_list[i])
|
||||||
before_words = before_words[:left]
|
before_words = before_words[:left]
|
||||||
return before[len(before_words):].strip()
|
return before[len(before_words):].strip()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user