-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_Compl.vim
More file actions
93 lines (81 loc) · 1.99 KB
/
python_Compl.vim
File metadata and controls
93 lines (81 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
" Author: justff
if v:version < 700
echoerr 'vim 7.0 required'
endif
if exists("b:did_PyCompl")
finish
endif
let b:did_PyCompl = 1
function Find(direction)
if pumvisible()
if a:direction == 'Down'
return "\<C-N>"
else
return "\<C-P>"
endif
else
return "\<C-X>\<C-O>"
endif
let b:pos = col('.') - 2
let b:line = getline('.')
if b:line[b:pos] != '.'
return "\<Tab>"
endif
endfunc
function PyComplFunc(findstart, base)
if a:findstart
let b:pos = col('.') - 2
let b:line = getline('.')
while b:pos > 0 && b:line[b:pos - 1] =~ '\w'
let b:pos -= 1
endwhile
return b:pos
else
return MakeDict(a:base)
endfunction
set omnifunc=PyComplFunc
inoremap <buffer><silent> <Tab> <C-R>=Find('Down')<CR>
inoremap <buffer><silent> <S-Tab> <C-R>=Find('Up')<CR>
function MakeDict(base)
python << EOF
import vim
modules = set()
depend_dict = {}
def makeDependecy():
for line in vim.current.buffer:
if line.startswith('from'):
part = line.split(' ', 3)
if part[0] == 'from' and part[2] == 'import':
module = part[1]
modules.add(module.strip())
for method in part[3].split(','):
depend_dict[method.strip()] = module
if line.startswith('import'):
part = line.split(' ', 1)
if part[0] == 'import':
for module in part[1].split(','):
modules.add(module.strip())
def makeList(prefix):
part = prefix.split()[-1].split('.')
mod = part[0]
while mod in depend_dict:
tmp = depend_dict[mod]
if tmp == mod:
break
else:
mod = tmp
if mod in modules:
obj = __import__(mod)
for i in part[1:-2]:
obj = getattr(obj, i)
header = prefix[:len(prefix)-len(part[-1])]
return [header + entry for entry in dir(obj) if entry.startswith(part[-1])]
return []
if __name__ == '__main__':
makeDependecy()
prefix = vim.eval("a:base").strip()
res = makeList(prefix)
vim.command("let b:result_list = " + str(res))
EOF
return b:result_list
endfunction