mirror of
https://github.com/amix/vimrc
synced 2025-06-17 10:55:00 +08:00
Updated plugins
This commit is contained in:
@ -1,25 +1,28 @@
|
||||
"""Helper methods used in UltiSnips snippets."""
|
||||
|
||||
import string, vim
|
||||
import string, vim, re
|
||||
|
||||
def complete(tab, opts):
|
||||
"""
|
||||
get options that start with tab
|
||||
get options that match with tab
|
||||
|
||||
:param tab: query string
|
||||
:param opts: list that needs to be completed
|
||||
|
||||
:return: a string that start with tab
|
||||
:return: a string that match with tab
|
||||
"""
|
||||
msg = "({0})"
|
||||
if tab:
|
||||
opts = [m[len(tab):] for m in opts if m.startswith(tab)]
|
||||
if len(opts) == 1:
|
||||
return opts[0]
|
||||
|
||||
if not len(opts):
|
||||
msg = "{0}"
|
||||
return msg.format("|".join(opts))
|
||||
el = [x for x in tab]
|
||||
pat = "".join(list(map(lambda x: x + "\w*" if re.match("\w", x) else x,
|
||||
el)))
|
||||
try:
|
||||
opts = [x for x in opts if re.search(pat, x, re.IGNORECASE)]
|
||||
except:
|
||||
opts = [x for x in opts if x.startswith(tab)]
|
||||
if not len(opts) or str.lower(tab) in list(map(str.lower, opts)):
|
||||
return ""
|
||||
cads = "|".join(opts[:5])
|
||||
if len(opts) > 5: cads += "|..."
|
||||
return "({0})".format(cads)
|
||||
|
||||
def _parse_comments(s):
|
||||
""" Parses vim's comments option to extract comment format """
|
||||
@ -69,7 +72,7 @@ def get_comment_format():
|
||||
commentstring = vim.eval("&commentstring")
|
||||
if commentstring.endswith("%s"):
|
||||
c = commentstring[:-2]
|
||||
return (c, c, c, "")
|
||||
return (c.rstrip(), c.rstrip(), c.rstrip(), "")
|
||||
comments = _parse_comments(vim.eval("&comments"))
|
||||
for c in comments:
|
||||
if c[0] == "SINGLE_CHAR":
|
||||
@ -90,3 +93,26 @@ def make_box(twidth, bwidth=None):
|
||||
def foldmarker():
|
||||
"Return a tuple of (open fold marker, close fold marker)"
|
||||
return vim.eval("&foldmarker").split(",")
|
||||
|
||||
|
||||
def display_width(str):
|
||||
"""Return the required over-/underline length for str."""
|
||||
try:
|
||||
# Respect &ambiwidth and &tabstop, but old vim may not support this
|
||||
return vim.strdisplaywidth(str)
|
||||
except AttributeError:
|
||||
# Fallback
|
||||
from unicodedata import east_asian_width
|
||||
result = 0
|
||||
for c in str:
|
||||
result += 2 if east_asian_width(c) in ('W', 'F') else 1
|
||||
return result
|
||||
|
||||
# http://stackoverflow.com/questions/2718196/find-all-chinese-text-in-a-string-using-python-and-regex
|
||||
def has_cjk(s):
|
||||
"""Detect if s contains CJK characters."""
|
||||
cjk_re = re.compile(u'[⺀-⺙⺛-⻳⼀-⿕々〇〡-〩〸-〺〻㐀-䶵一-鿃豈-鶴侮-頻並-龎]', re.UNICODE)
|
||||
|
||||
return cjk_re.search(s) is not None
|
||||
|
||||
# vim:set et sts=0 sw=4 ts=4:
|
||||
|
Reference in New Issue
Block a user