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().
This commit is contained in:
parent
84050b4b8d
commit
5eaa61ae27
@ -42,18 +42,9 @@ INCLUDABLE_DIRECTIVES = ['image', 'figure', 'include']
|
|||||||
CJK_RE = re.compile(u'[⺀-⺙⺛-⻳⼀-⿕々〇〡-〩〸-〺〻㐀-䶵一-鿃豈-鶴侮-頻並-龎]', re.UNICODE)
|
CJK_RE = re.compile(u'[⺀-⺙⺛-⻳⼀-⿕々〇〡-〩〸-〺〻㐀-䶵一-鿃豈-鶴侮-頻並-龎]', re.UNICODE)
|
||||||
|
|
||||||
|
|
||||||
def has_cjk(char):
|
def has_cjk(s):
|
||||||
"""
|
"""Detect if s contains CJK characters."""
|
||||||
Detect char contains CJK character
|
return CJK_RE.search(s) is not None
|
||||||
|
|
||||||
:param char: characters needs to be detect
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
CJK_RE.finditer(char).next()
|
|
||||||
except StopIteration:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
def real_filename(filename):
|
def real_filename(filename):
|
||||||
"""pealeextension name off if possible
|
"""pealeextension name off if possible
|
||||||
@ -182,7 +173,7 @@ endsnippet
|
|||||||
|
|
||||||
snippet em "Emphasize string" i
|
snippet em "Emphasize string" i
|
||||||
`!p
|
`!p
|
||||||
# dirty but works with CJK charactor detection
|
# dirty but works with CJK character detection
|
||||||
if has_cjk(vim.current.line):
|
if has_cjk(vim.current.line):
|
||||||
snip.rv ="\ "`*${1:${VISUAL:Em}}*`!p
|
snip.rv ="\ "`*${1:${VISUAL:Em}}*`!p
|
||||||
if has_cjk(vim.current.line):
|
if has_cjk(vim.current.line):
|
||||||
|
Loading…
Reference in New Issue
Block a user