Skip to content

Commit decb14d

Browse files
committed
Update channel.txt
1 parent b6b5252 commit decb14d

File tree

1 file changed

+56
-22
lines changed

1 file changed

+56
-22
lines changed

runtime/doc/channel.txt

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ Use |ch_status()| to see if the channel could be opened.
121121
"nl" - Use messages that end in a NL character
122122
"raw" - Use raw messages
123123

124+
"in-mode" mode specifically for stdin, only when using pipes
125+
"out-mode" mode specifically for stdout, only when using pipes
126+
"err-mode" mode specifically for stderr, only when using pipes
127+
Note: when setting "mode" the part specific mode is
128+
overwritten. Therefore set "mode" first and the part specific
129+
mode later.
130+
124131
*channel-callback*
125132
"callback" A function that is called when a message is received that is
126133
not handled otherwise. It gets two arguments: the channel
@@ -130,9 +137,13 @@ Use |ch_status()| to see if the channel could be opened.
130137
endfunc
131138
let channel = ch_open("localhost:8765", {"callback": "Handle"})
132139
<
133-
TODO:
140+
"out-cb" A function like "callback" but used for stdout. Only for when
141+
the channel uses pipes. When "out-cb" wasn't set the channel
142+
callback is used.
143+
134144
"err-cb" A function like "callback" but used for stderr. Only for when
135-
the channel uses pipes.
145+
the channel uses pipes. When "err-cb" wasn't set the channel
146+
callback is used.
136147

137148
TODO:
138149
"close-cb" A function that is called when the channel gets closed, other
@@ -144,10 +155,16 @@ Use |ch_status()| to see if the channel could be opened.
144155
useful if the server is supposed to be running already. A
145156
negative number waits forever.
146157

147-
"timeout" The time to wait for a request when blocking, using
148-
ch_sendexpr(). Again in milliseconds. The default is 2000 (2
158+
"timeout" The time to wait for a request when blocking, E.g. when using
159+
ch_sendexpr(). In milliseconds. The default is 2000 (2
149160
seconds).
150161

162+
"out-timeout" Timeout for stdout. Only when using pipes.
163+
"err-timeout" Timeout for stderr. Only when using pipes.
164+
Note: when setting "timeout" the part specific mode is
165+
overwritten. Therefore set "timeout" first and the part
166+
specific mode later.
167+
151168
When "mode" is "json" or "js" the "msg" argument is the body of the received
152169
message, converted to Vim types.
153170
When "mode" is "raw" the "msg" argument is the whole message as a string.
@@ -248,8 +265,10 @@ Possible commands are: *E903* *E904* *E905*
248265
["redraw" {forced}]
249266
["ex", {Ex command}]
250267
["normal", {Normal mode command}]
251-
["eval", {expression}, {number}]
268+
["expr", {expression}, {number}]
252269
["expr", {expression}]
270+
["call", {func name}, {argument list}, {number}]
271+
["call", {func name}, {argument list}]
253272

254273
With all of these: Be careful what these commands do! You can easily
255274
interfere with what the user is doing. To avoid trouble use |mode()| to check
@@ -290,29 +309,44 @@ mapped. Example to open the folds under the cursor:
290309
["normal" "zO"]
291310

292311

293-
Command "eval" ~
312+
Command "expr" with response ~
294313

295-
The "eval" command an be used to get the result of an expression. For
314+
The "expr" command can be used to get the result of an expression. For
296315
example, to get the number of lines in the current buffer:
297-
["eval","line('$')", -2] ~
316+
["expr","line('$')", -2] ~
298317

299-
it will send back the result of the expression:
318+
It will send back the result of the expression:
300319
[-2, "last line"] ~
301320
The format is:
302321
[{number}, {result}]
322+
*E915*
303323
Here {number} is the same as what was in the request. Use a negative number
304-
to avoid confusion with message that Vim sends.
324+
to avoid confusion with message that Vim sends. Use a different number on
325+
every request to be able to match the request with the response.
305326

306327
{result} is the result of the evaluation and is JSON encoded. If the
307328
evaluation fails or the result can't be encoded in JSON it is the string
308329
"ERROR".
309330

310331

311-
Command "expr" ~
332+
Command "expr" without a response ~
312333

313-
The "expr" command is similar to "eval", but does not send back any response.
334+
This command is similar to "expr" above, but does not send back any response.
314335
Example:
315336
["expr","setline('$', ['one', 'two', 'three'])"] ~
337+
There is no third argument in the request.
338+
339+
340+
Command "call" ~
341+
342+
This is similar to "expr", but instead of passing the whole expression as a
343+
string this passes the name of a function and a list of arguments. This
344+
avoids the conversion of the arguments to a string and escaping and
345+
concatenating them. Example:
346+
["call", "line", ["$"], -2] ~
347+
348+
Leave out the fourth argument if no response is to be sent:
349+
["call", "setline", ["$", ["one", "two", "three"]]] ~
316350

317351
==============================================================================
318352
6. Using a RAW or NL channel *channel-raw*
@@ -357,20 +391,18 @@ are:
357391
TODO:
358392
To objain the job associated with a channel: ch_getjob(channel)
359393

360-
TODO:
361394
To read one message from a channel: >
362395
let output = ch_read(channel)
363396
This uses the channel timeout. To read without a timeout, just get any
364397
message that is available: >
365-
let output = ch_read(channel, 0)
398+
let output = ch_read(channel, {'timeout': 0})
366399
When no message was available then the result is v:none for a JSON or JS mode
367400
channels, an empty string for a RAW or NL channel.
368401

369-
To read all output from a RAW or NL channel that is available: >
370-
let output = ch_readall(channel)
402+
To read all output from a RAW channel that is available: >
403+
let output = ch_readraw(channel)
371404
To read the error output: >
372-
let output = ch_readall(channel, "err")
373-
TODO: use channel timeout, no timeout or specify timeout?
405+
let output = ch_readraw(channel, {"part": "err"})
374406
375407
==============================================================================
376408
8. Starting a job with a channel *job-start* *job*
@@ -451,13 +483,15 @@ This gives the job some time to make the port available.
451483
The {options} argument in job_start() is a dictionary. All entries are
452484
optional. The same options can be used with job_setoptions(job, {options}).
453485

454-
TODO: *job-out-cb*
455-
"callback": handler
486+
*job-callback*
487+
"callback": handler Callback for something to read on any part of the
488+
channel.
489+
*job-out-cb*
456490
"out-cb": handler Callback for when there is something to read on
457491
stdout.
458-
TODO: *job-err-cb*
492+
*job-err-cb*
459493
"err-cb": handler Callback for when there is something to read on
460-
stderr. Defaults to the same callback as "out-cb".
494+
stderr.
461495
TODO: *job-close-cb*
462496
"close-cb": handler Callback for when the channel is closed. Same as
463497
"close-cb" on ch_open().

0 commit comments

Comments
 (0)