comparison runtime/doc/channel.txt @ 27903:d19b7aee1925

Update runtime files. Commit: https://github.com/vim/vim/commit/c51cf0329809c7ae946c59d6f56699227efc9d1b Author: Bram Moolenaar <Bram@vim.org> Date: Sat Feb 26 12:25:45 2022 +0000 Update runtime files.
author Bram Moolenaar <Bram@vim.org>
date Sat, 26 Feb 2022 13:30:04 +0100
parents c725b8e17f1f
children c968191a8557
comparison
equal deleted inserted replaced
27902:8481c8908b5e 27903:d19b7aee1925
89 And you should see the message in Vim. You can move the cursor a word forward: 89 And you should see the message in Vim. You can move the cursor a word forward:
90 ["normal","w"] ~ 90 ["normal","w"] ~
91 91
92 To handle asynchronous communication a callback needs to be used: > 92 To handle asynchronous communication a callback needs to be used: >
93 func MyHandler(channel, msg) 93 func MyHandler(channel, msg)
94 echo "from the handler: " . a:msg 94 echo "from the handler: " .. a:msg
95 endfunc 95 endfunc
96 call ch_sendexpr(channel, 'hello!', {'callback': "MyHandler"}) 96 call ch_sendexpr(channel, 'hello!', {'callback': "MyHandler"})
97 Vim will not wait for a response. Now the server can send the response later 97 Vim will not wait for a response. Now the server can send the response later
98 and MyHandler will be invoked. 98 and MyHandler will be invoked.
99 99
134 "callback" A function that is called when a message is received that is 134 "callback" A function that is called when a message is received that is
135 not handled otherwise (e.g. a JSON message with ID zero). It 135 not handled otherwise (e.g. a JSON message with ID zero). It
136 gets two arguments: the channel and the received message. 136 gets two arguments: the channel and the received message.
137 Example: > 137 Example: >
138 func Handle(channel, msg) 138 func Handle(channel, msg)
139 echo 'Received: ' . a:msg 139 echo 'Received: ' .. a:msg
140 endfunc 140 endfunc
141 let channel = ch_open("localhost:8765", {"callback": "Handle"}) 141 let channel = ch_open("localhost:8765", {"callback": "Handle"})
142 < 142 <
143 When "mode" is "json" or "js" the "msg" argument is the body 143 When "mode" is "json" or "js" the "msg" argument is the body
144 of the received message, converted to Vim types. 144 of the received message, converted to Vim types.
1294 call ch_sendraw(g:shell_job, a:text .. "\n") 1294 call ch_sendraw(g:shell_job, a:text .. "\n")
1295 endfunc 1295 endfunc
1296 1296
1297 " Function handling output from the shell: Added above the prompt. 1297 " Function handling output from the shell: Added above the prompt.
1298 func GotOutput(channel, msg) 1298 func GotOutput(channel, msg)
1299 call append(line("$") - 1, "- " . a:msg) 1299 call append(line("$") - 1, "- " .. a:msg)
1300 endfunc 1300 endfunc
1301 1301
1302 " Function handling the shell exist: close the window. 1302 " Function handling the shell exist: close the window.
1303 func JobExit(job, status) 1303 func JobExit(job, status)
1304 quit! 1304 quit!