Fixed bug 1034805: Langmap with escaped characters where a problem

This commit is contained in:
Holger Rapp 2012-08-15 14:13:50 +02:00
parent aae704bd1a
commit b319569b7b
2 changed files with 46 additions and 8 deletions

View File

@ -4,6 +4,8 @@
""" """
Wrapper functionality around the functions we need from Vim Wrapper functionality around the functions we need from Vim
""" """
import re
import vim import vim
from vim import error from vim import error
@ -277,12 +279,16 @@ class _Real_LangMapTranslator(object):
one line down is no longer possible and UltiSnips will fail. one line down is no longer possible and UltiSnips will fail.
""" """
_maps = {} _maps = {}
_SEMICOLONS = re.compile(r"(?<!\\);")
_COMMA = re.compile(r"(?<!\\),")
def _create_translation(self, langmap): def _create_translation(self, langmap):
from_chars, to_chars = "", "" from_chars, to_chars = "", ""
for c in langmap.split(','): for c in self._COMMA.split(langmap):
if ";" in c: c = c.replace("\\,", ",")
a,b = c.split(';') res = self._SEMICOLONS.split(c)
if len(res) > 1:
a,b = map(lambda a: a.replace("\\;", ";"), res)
from_chars += a from_chars += a
to_chars += b to_chars += b
else: else:

42
test.py
View File

@ -36,6 +36,7 @@ import time
import re import re
import platform import platform
import sys import sys
import subprocess
from textwrap import dedent from textwrap import dedent
@ -79,7 +80,7 @@ class VimInterface:
os.close(handle) os.close(handle)
os.unlink(fn) os.unlink(fn)
self.send(":w! %s\n" % fn) self.send(ESC + ":w! %s\n" % fn)
# Read the output, chop the trailing newline # Read the output, chop the trailing newline
tries = 50 tries = 50
@ -102,11 +103,19 @@ class VimInterfaceScreen(VimInterface):
s = re.sub( r"[$^#\\']", repl, s ) s = re.sub( r"[$^#\\']", repl, s )
# Escape single quotes in command to protect from shell # Escape single quotes in command to protect from shell
s = s.replace("'", r"'\''")
cmd = "screen -x %s -X stuff '%s'" % (self.session, s)
if sys.version_info >= (3,0): if sys.version_info >= (3,0):
cmd = cmd.encode("utf-8") s = s.encode("utf-8")
os.system(cmd)
silent_call = lambda cmd: subprocess.call(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
while True:
rv = 0
if len(s) > 30:
rv |= silent_call(["screen", "-x", self.session, "-X", "register", "S", s])
rv |= silent_call(["screen", "-x", self.session, "-X", "paste", "S"])
else:
rv |= silent_call(["screen", "-x", self.session, "-X", "stuff", s])
if not rv: break
time.sleep(.2)
def detect_parsing(self): def detect_parsing(self):
# Clear the buffer # Clear the buffer
@ -249,6 +258,9 @@ class _VimTest(unittest.TestCase):
if self.skip_on_mac and system == "Darwin": if self.skip_on_mac and system == "Darwin":
return self._skip("Running on Darwin/Mac") return self._skip("Running on Darwin/Mac")
# Escape for good measure
self.send(ESC + ESC + ESC)
# Close all scratch buffers # Close all scratch buffers
self.send(":silent! close\n") self.send(":silent! close\n")
@ -2445,6 +2457,24 @@ hi4"""
def _options_off(self): def _options_off(self):
self.send(":set langmap=\n") self.send(":set langmap=\n")
# Test for bug 501727 #
class TestNonEmptyLangmapWithSemi_ExceptCorrectResult(_VimTest):
snippets = ("testme",
"""my snipped ${1:some_default}
and a mirror: $1
$2...$3
$0""")
keys = "testme" + EX + "hi;" + JF + "hi2" + JF + "hi3" + JF + "hi4" + ESC + ";Hello"
wanted ="""my snipped hi;
and a mirror: hi;
hi2...hi3
hi4Hello"""
def _options_on(self):
self.send(":set langmap=\\\\;;A\n")
def _options_off(self):
self.send(":set langmap=\n")
# Test for bug 871357 # # Test for bug 871357 #
class TestLangmapWithUtf8_ExceptCorrectResult(_VimTest): class TestLangmapWithUtf8_ExceptCorrectResult(_VimTest):
skip_on_windows = True # SendKeys can't send UTF characters skip_on_windows = True # SendKeys can't send UTF characters
@ -2946,6 +2976,8 @@ if __name__ == '__main__':
vim.focus() vim.focus()
vim.send(ESC)
# Ensure we are not running in VI-compatible mode. # Ensure we are not running in VI-compatible mode.
vim.send(""":set nocompatible\n""") vim.send(""":set nocompatible\n""")