From 5eaa61ae275931a8336542ddeccb43a6b20e95a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Neum=C3=BCller?= Date: Sat, 26 Jul 2014 10:20:06 +0200 Subject: [PATCH] rst: Make has_cjk() Python 3 compatible. In Python 3, iterators no longer have a next() method: it has been renamed to __next__(). This could be worked around by using the builtin function next(), but a simpler fix is to just use the regex' object search() method instead of finditer(). --- UltiSnips/rst.snippets | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/UltiSnips/rst.snippets b/UltiSnips/rst.snippets index 624b201..b73a8b9 100644 --- a/UltiSnips/rst.snippets +++ b/UltiSnips/rst.snippets @@ -42,18 +42,9 @@ INCLUDABLE_DIRECTIVES = ['image', 'figure', 'include'] CJK_RE = re.compile(u'[⺀-⺙⺛-⻳⼀-⿕々〇〡-〩〸-〺〻㐀-䶵一-鿃豈-鶴侮-頻並-龎]', re.UNICODE) -def has_cjk(char): - """ - Detect char contains CJK character - - :param char: characters needs to be detect - """ - try: - CJK_RE.finditer(char).next() - except StopIteration: - return False - else: - return True +def has_cjk(s): + """Detect if s contains CJK characters.""" + return CJK_RE.search(s) is not None def real_filename(filename): """pealeextension name off if possible @@ -182,7 +173,7 @@ endsnippet snippet em "Emphasize string" i `!p -# dirty but works with CJK charactor detection +# dirty but works with CJK character detection if has_cjk(vim.current.line): snip.rv ="\ "`*${1:${VISUAL:Em}}*`!p if has_cjk(vim.current.line):