1 # From http://slobin.pp.ru/vim/_vimrc.html
2 # Adapted to python3 by Oleg Broytman <phd@phdru.name>
4 from itertools import count
12 vim_complete = rlcompleter.Completer().complete
16 """Implementation of CompList() function"""
17 arglead = vim.eval("a:ArgLead")
18 fence = int(vim.eval("match(a:ArgLead, '\\(\\w\\|\\.\\)*$')"))
19 left, right = arglead[:fence], arglead[fence:]
21 completions = (vim_complete(right, i) for i in count())
22 candidates = list(takewhile(bool, completions))
25 suggestions = [left + x for x in candidates]
26 vim.command("return " + repr(suggestions))
29 def vim_calc(command):
30 """Implementation of :Calc command"""
33 result = eval(command)
35 if sys.version_info[0] == 2:
36 exec(command in globals(), locals())
38 exec(command, globals(), locals())
40 if result is not None:
43 xx = ''.join(['\\x%02x' % ord(x) for x in str(_)])
44 vim.command('let @" = "%s"' % xx)
47 def vim_pydo(command):
48 """Implementation of :Pydo command"""
49 codeobj = compile(command, "command", "eval")
50 line1 = vim.current.range.start
51 line2 = vim.current.range.end
53 for numz in range(line1, line2+1):
54 line = vim.current.buffer[numz-delta]
55 if sys.version_info[0] == 2:
56 uline = line.decode(vim.eval('&fileencoding'))
61 result = eval(codeobj, globals(), locals())
62 if result is None or result is False:
63 del vim.current.buffer[numz-delta]
66 if isinstance(result, list) or isinstance(result, tuple):
67 result = " ".join(map(str, result))
70 vim.current.buffer[numz-delta] = result
73 def vim_unicode_name():
75 char = vim.eval("matchstr(getline('.'), '.', col('.') - 1)")
76 if sys.version_info[0] == 2:
77 print(unicodedata.name(char.decode(vim.eval("&encoding"))))
79 print(unicodedata.name(char))
80 except (AttributeError, ValueError) as target:
81 print("%s: %s" % (target.__class__.__name__, target))