11
22
33if has (' pythonx' )
4- let s: py= ' pythonx'
5- let s: pyeval= function (' pyxeval' )
4+ let s: py= ' pythonx'
5+ let s: pyeval= function (' pyxeval' )
66elseif has (' python3' )
7- let s: py= ' python3'
8- let s: pyeval= function (' py3eval' )
7+ let s: py= ' python3'
8+ let s: pyeval= function (' py3eval' )
99else
10- let s: py= ' python'
11- let s: pyeval= function (' pyeval' )
10+ let s: py= ' python'
11+ let s: pyeval= function (' pyeval' )
1212endif
1313
1414func ! neovim_rpc#serveraddr ()
15- if exists (' g:_neovim_rpc_nvim_server' )
16- return g: _neovim_rpc_nvim_server
17- endif
15+ if exists (' g:_neovim_rpc_nvim_server' )
16+ return g: _neovim_rpc_nvim_server
17+ endif
1818
1919" must be utf-8
2020if &encoding !=? " utf-8"
@@ -29,28 +29,28 @@ func! neovim_rpc#serveraddr()
2929throw ' [vim-hug-neovim-rpc] requires `:' .s: py .' import neovim` command to work'
3030endtry
3131
32- execute s: py .' import neovim_rpc_server'
33- let l: servers= s: pyeval (' neovim_rpc_server.start()' )
32+ execute s: py .' import neovim_rpc_server'
33+ let l: servers= s: pyeval (' neovim_rpc_server.start()' )
3434
35- let g: _neovim_rpc_nvim_server= l: servers [0 ]
36- let g: _neovim_rpc_vim_server= l: servers [1 ]
35+ let g: _neovim_rpc_nvim_server= l: servers [0 ]
36+ let g: _neovim_rpc_vim_server= l: servers [1 ]
3737
38- let g: _neovim_rpc_main_channel= ch_open (g: _neovim_rpc_vim_server )
38+ let g: _neovim_rpc_main_channel= ch_open (g: _neovim_rpc_vim_server )
3939
40- " close channel before vim exit
41- " au VimLeavePre * let s:leaving = 1 | execute s:py . ' neovim_rpc_server.stop()'
40+ " close channel before vim exit
41+ " au VimLeavePre * let s:leaving = 1 | execute s:py . ' neovim_rpc_server.stop()'
4242
43- " identify myself
44- call ch_sendexpr (g: _neovim_rpc_main_channel ,' neovim_rpc_setup' )
43+ " identify myself
44+ call ch_sendexpr (g: _neovim_rpc_main_channel ,' neovim_rpc_setup' )
4545
46- return g: _neovim_rpc_nvim_server
46+ return g: _neovim_rpc_nvim_server
4747endfunc
4848
4949" elegant python function call wrapper
5050func ! neovim_rpc#pyxcall (func ,... )
51- execute s: py .' import vim, json'
51+ execute s: py .' import vim, json'
5252let g: neovim_rpc #_tmp_args= copy (a: 000 )
53- let l: ret= s: pyeval (a: func .' (*vim.vars["neovim_rpc#_tmp_args"])' )
53+ let l: ret= s: pyeval (a: func .' (*vim.vars["neovim_rpc#_tmp_args"])' )
5454unlet g: neovim_rpc #_tmp_args
5555return l: ret
5656endfunc
@@ -62,43 +62,43 @@ endfunc
6262" - detach
6363func ! neovim_rpc#jobstart (cmd,... )
6464
65- let l: opts= {}
66- if len (a: 000 )
67- let l: opts= a: 1
68- endif
65+ let l: opts= {}
66+ if len (a: 000 )
67+ let l: opts= a: 1
68+ endif
6969
7070let l: opts [' _close' ]= 0
7171let l: opts [' _exit' ]= 0
7272
73- let l: real_opts= {' mode' :' raw' }
74- if has_key (l: opts ,' detach' )&& l: opts [' detach' ]
75- let l: real_opts [' stoponexit' ]= ' '
76- endif
77-
78- if has_key (l: opts ,' on_stdout' )
79- let l: real_opts [' out_cb' ]= function (' neovim_rpc#_on_stdout' )
80- endif
81- if has_key (l: opts ,' on_stderr' )
82- let l: real_opts [' err_cb' ]= function (' neovim_rpc#_on_stderr' )
83- endif
73+ let l: real_opts= {' mode' :' raw' }
74+ if has_key (l: opts ,' detach' )&& l: opts [' detach' ]
75+ let l: real_opts [' stoponexit' ]= ' '
76+ endif
77+
78+ if has_key (l: opts ,' on_stdout' )
79+ let l: real_opts [' out_cb' ]= function (' neovim_rpc#_on_stdout' )
80+ endif
81+ if has_key (l: opts ,' on_stderr' )
82+ let l: real_opts [' err_cb' ]= function (' neovim_rpc#_on_stderr' )
83+ endif
8484let l: real_opts [' exit_cb' ]= function (' neovim_rpc#_on_exit' )
8585let l: real_opts [' close_cb' ]= function (' neovim_rpc#_on_close' )
8686
87- let l: job= job_start (a: cmd ,l: real_opts )
88- let l: jobid= ch_info (l: job )[' id' ]
87+ let l: job= job_start (a: cmd ,l: real_opts )
88+ let l: jobid= ch_info (l: job )[' id' ]
8989
90- let g: _neovim_rpc_jobs [l: jobid ]= {' cmd' :a: cmd ,' opts' :l: opts ,' job' :l: job }
90+ let g: _neovim_rpc_jobs [l: jobid ]= {' cmd' :a: cmd ,' opts' :l: opts ,' job' :l: job }
9191
92- return l: jobid
92+ return l: jobid
9393endfunc
9494
9595func ! neovim_rpc#jobstop (jobid)
96- let l: job= g: _neovim_rpc_jobs [a: jobid ][' job' ]
97- return job_stop (l: job )
96+ let l: job= g: _neovim_rpc_jobs [a: jobid ][' job' ]
97+ return job_stop (l: job )
9898endfunc
9999
100100func ! neovim_rpc#rpcnotify (channel,event ,... )
101- call neovim_rpc#pyxcall (' neovim_rpc_server.rpcnotify' ,a: channel ,a: event ,a: 000 )
101+ call neovim_rpc#pyxcall (' neovim_rpc_server.rpcnotify' ,a: channel ,a: event ,a: 000 )
102102endfunc
103103
104104let s: rspid= 1
@@ -115,7 +115,7 @@ func! neovim_rpc#rpcrequest(channel, event, ...)
115115
116116let expr = ' json.dumps(neovim_rpc_server.responses.pop("' . rspid .' "))'
117117
118- execute s: py' import neovim_rpc_server, json'
118+ execute s: py' import neovim_rpc_server, json'
119119let [err, result]= json_decode (s: pyeval (expr ))
120120if err
121121if type (err)== type (' ' )
@@ -127,22 +127,22 @@ func! neovim_rpc#rpcrequest(channel, event, ...)
127127endfunc
128128
129129func ! neovim_rpc#_on_stdout (job,data)
130- let l: jobid= ch_info (a: job )[' id' ]
131- let l: opts= g: _neovim_rpc_jobs [l: jobid ][' opts' ]
132- " convert to neovim style function call
133- call call (l: opts [' on_stdout' ],[l: jobid ,split (a: data ," \n " ,1 ),' stdout' ],l: opts )
130+ let l: jobid= ch_info (a: job )[' id' ]
131+ let l: opts= g: _neovim_rpc_jobs [l: jobid ][' opts' ]
132+ " convert to neovim style function call
133+ call call (l: opts [' on_stdout' ],[l: jobid ,split (a: data ," \n " ,1 ),' stdout' ],l: opts )
134134endfunc
135135
136136func ! neovim_rpc#_on_stderr (job,data)
137- let l: jobid= ch_info (a: job )[' id' ]
138- let l: opts= g: _neovim_rpc_jobs [l: jobid ][' opts' ]
139- " convert to neovim style function call
140- call call (l: opts [' on_stderr' ],[l: jobid ,split (a: data ," \n " ,1 ),' stderr' ],l: opts )
137+ let l: jobid= ch_info (a: job )[' id' ]
138+ let l: opts= g: _neovim_rpc_jobs [l: jobid ][' opts' ]
139+ " convert to neovim style function call
140+ call call (l: opts [' on_stderr' ],[l: jobid ,split (a: data ," \n " ,1 ),' stderr' ],l: opts )
141141endfunc
142142
143143func ! neovim_rpc#_on_exit (job,status)
144- let l: jobid= ch_info (a: job )[' id' ]
145- let l: opts= g: _neovim_rpc_jobs [l: jobid ][' opts' ]
144+ let l: jobid= ch_info (a: job )[' id' ]
145+ let l: opts= g: _neovim_rpc_jobs [l: jobid ][' opts' ]
146146let l: opts [' _exit' ]= 1
147147" cleanup when both close_cb and exit_cb is called
148148if l: opts [' _close' ]&& l: opts [' _exit' ]
@@ -155,8 +155,8 @@ func! neovim_rpc#_on_exit(job,status)
155155endfunc
156156
157157func ! neovim_rpc#_on_close (job)
158- let l: jobid= ch_info (a: job )[' id' ]
159- let l: opts= g: _neovim_rpc_jobs [l: jobid ][' opts' ]
158+ let l: jobid= ch_info (a: job )[' id' ]
159+ let l: opts= g: _neovim_rpc_jobs [l: jobid ][' opts' ]
160160let l: opts [' _close' ]= 1
161161" cleanup when both close_cb and exit_cb is called
162162if l: opts [' _close' ]&& l: opts [' _exit' ]
@@ -165,7 +165,7 @@ func! neovim_rpc#_on_close(job)
165165endfunc
166166
167167func ! neovim_rpc#_callback ()
168- execute s: py .' neovim_rpc_server.process_pending_requests()'
168+ execute s: py .' neovim_rpc_server.process_pending_requests()'
169169endfunc
170170
171171let g: _neovim_rpc_main_channel= -1