-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector.vim
117 lines (92 loc) · 2.16 KB
/
vector.vim
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
function! VectorSerVar(os)
if a:os == "windows"
let g:vector_ip = "192.168.3.116"
else
let g:vector_ip = "192.168.3.115"
endif
let g:vector_port = "20000"
echom 'ip:'.g:vector_ip .' port: '. g:vector_port
endfunction
function! Vector(how)
if a:how == "all"
let msg = join(getline(1,'$'), "\n")
else
let msg = VectorMethod()
" line 2 have methods ?
" last line have "," ?
let msg = substitute(msg, ".create",".recreate","").split("\n")
echom msg[1]
return
endif
" first line have .create ?
msg = substitute(msg, ".create",".recreate","")
call VectorSend(g:vector_ip, g:vector_port, msg)
endfunction
function! VectorMethod()
python3 << EOF
import vim
import re
vim.command("let sline = 1")
vim.command("let fline = 2")
buffer = vim.current.buffer
window = vim.current.window
cursor = window.cursor
vim.command('normal [{')
cline = window.cursor[0]-1
line = buffer[cline]
oline = cline
while re.match( r'^\t*(methods)? *:.*=> %q{',line) == None:
vim.command('normal [{')
cline = window.cursor[0]-1
if oline == cline:
print("Dont found start method")
#return ""
break
oline = cline
line = buffer[cline]
sline = cline
vim.command('let sline = ' + str(sline+1))
vim.command('normal ]}')
cline = window.cursor[0]-1
if cline == oline:
print("Dont found stop method")
line = buffer[cline]
oline = cline
while re.match(r'^\t*},?',line) == None:
vim.command('normal ]}')
cline = window.cursor[0]-1
if oline == cline:
print("Dont found stop method")
#return ""
break
oline = cline
line = buffer[cline]
eline = cline
vim.command('let eline = ' + str(eline+1))
window.cursor = cursor
EOF
let msg = getline(1) . "\n". join(getline(sline,eline),"\n")
return msg
endfunction
function! VectorHello()
let str = 'print "hello"'
call VectorSend(g:vector_ip, g:vector_port, str)
endfunction
function! VectorSend(ip, port, msg)
python3 << EOF
import vim
import socket
ip = vim.eval("a:ip")
port = int(vim.eval("a:port"))
msg = vim.eval("a:msg")
sock = socket.socket()
sock.connect((ip, port))
sock.send(msg.encode("utf-8") + b'\n# TCP-END\n')
sock.close
EOF
endfunction
function! VectorPrint(ip, port, msg)
echom a:ip
echom a:port
echom a:msg
endfunction