1- *channel.txt* For Vim version 7.4. Last change: 2016 Mar 15
1+ *channel.txt* For Vim version 7.4. Last change: 2016 Mar 26
22
33
44 VIM REFERENCE MANUAL by Bram Moolenaar
@@ -120,24 +120,13 @@ Use |ch_status()| to see if the channel could be opened.
120120
121121{address} has the form "hostname:port". E.g., "localhost:8765".
122122
123- {options} is a dictionary with optional entries:
123+ {options} is a dictionary with optional entries: *channel-open-options*
124124
125125"mode" can be: *channel-mode*
126126 "json" - Use JSON, see below; most convenient way. Default.
127127 "js" - Use JS (JavaScript) encoding, more efficient than JSON.
128128 "nl" - Use messages that end in a NL character
129129 "raw" - Use raw messages
130- *in_mode* *out_mode* *err_mode*
131- "in_mode" mode specifically for stdin, only when using pipes
132- "out_mode" mode specifically for stdout, only when using pipes
133- "err_mode" mode specifically for stderr, only when using pipes
134- Note: when setting "mode" the part specific mode is
135- overwritten. Therefore set "mode" first and the part specific
136- mode later.
137-
138- Note: when writing to a file or buffer and when reading from a
139- buffer NL mode is used by default.
140-
141130 *channel-callback* *E921*
142131"callback" A function that is called when a message is received that is
143132 not handled otherwise. It gets two arguments: the channel
@@ -155,16 +144,8 @@ Use |ch_status()| to see if the channel could be opened.
155144 as a string.
156145
157146 For all callbacks: Use | function() | to bind it to arguments
158- and/or a dictionary.
159- *out_cb*
160- "out_cb" A function like "callback" but used for stdout. Only for when
161- the channel uses pipes. When "out_cb" wasn't set the channel
162- callback is used.
163- *err_cb*
164- "err_cb" A function like "callback" but used for stderr. Only for when
165- the channel uses pipes. When "err_cb" wasn't set the channel
166- callback is used.
167-
147+ and/or a Dictionary. Or use the form "dict.function" to bind
148+ the Dictionary.
168149 *close_cb*
169150"close_cb" A function that is called when the channel gets closed, other
170151 than by calling ch_close(). It should be defined like this: >
@@ -178,16 +159,10 @@ Use |ch_status()| to see if the channel could be opened.
178159 actually uses a 1 msec timeout, that is required on many
179160 systems. Use a larger value for a remote server, e.g. 10
180161 msec at least.
181-
162+ *channel-timeout*
182163"timeout" The time to wait for a request when blocking, E.g. when using
183164 ch_evalexpr(). In milliseconds. The default is 2000 (2
184165 seconds).
185- *out_timeout* *err_timeout*
186- "out_timeout" Timeout for stdout. Only when using pipes.
187- "err_timeout" Timeout for stderr. Only when using pipes.
188- Note: when setting "timeout" the part specific mode is
189- overwritten. Therefore set "timeout" first and the part
190- specific mode later.
191166
192167When "mode" is "json" or "js" the "callback" is optional. When omitted it is
193168only possible to receive a message after sending one.
@@ -215,6 +190,13 @@ pipes are used (stdin/stdout/stderr) they are all closed. This might not be
215190what you want! Stopping the job with job_stop() might be better.
216191All readahead is discarded, callbacks will no longer be invoked.
217192
193+ Note that a channel is closed in three stages:
194+ - The I/O ends, log message: "Closing channel". There can still be queued
195+ messages to read or callbacks to invoke.
196+ - The readahead is cleared, log message: "Clearing channel". Some variables
197+ may still reference the channel.
198+ - The channel is freed, log message: "Freeing channel".
199+
218200When the channel can't be opened you will get an error message. There is a
219201difference between MS-Windows and Unix: On Unix when the port doesn't exist
220202ch_open() fails quickly. On MS-Windows "waittime" applies.
@@ -326,6 +308,9 @@ completion or error. You could use functions in an |autoload| script:
326308
327309You can also use "call | feedkeys() | " to insert any key sequence.
328310
311+ When there is an error a message is written to the channel log, if it exists,
312+ and v:errmsg is set to the error.
313+
329314
330315Command "normal" ~
331316
@@ -428,6 +413,23 @@ To read all output from a RAW channel that is available: >
428413 To read the error output: >
429414 let output = ch_readraw(channel, {"part": "err"})
430415
416+ ch_read() and ch_readraw() use the channel timeout. When there is nothing to
417+ read within that time an empty string is returned. To specify a different
418+ timeout in msec use the "timeout" option:
419+ {"timeout": 123} ~
420+ To read from the error output use the "part" option:
421+ {"part": "err"} ~
422+ To read a message with a specific ID, on a JS or JSON channel:
423+ {"id": 99} ~
424+ When no ID is specified or the ID is -1, the first message is returned. This
425+ overrules any callback waiting for this message.
426+
427+ For a RAW channel this returns whatever is available, since Vim does not know
428+ where a message ends.
429+ For a NL channel this returns one message.
430+ For a JS or JSON channel this returns one decoded message.
431+ This includes any sequence number.
432+
431433==============================================================================
4324348. Starting a job with a channel *job-start* *job*
433435
@@ -524,15 +526,31 @@ job_setoptions(job, {options}). Many options can be used with the channel
524526related to the job, using ch_setoptions(channel, {options} ).
525527See | job_setoptions() | and | ch_setoptions() | .
526528
529+ *in_mode* *out_mode* *err_mode*
530+ "in_mode" mode specifically for stdin, only when using pipes
531+ "out_mode" mode specifically for stdout, only when using pipes
532+ "err_mode" mode specifically for stderr, only when using pipes
533+ See | channel-mode | for the values.
534+
535+ Note: when setting "mode" the part specific mode is
536+ overwritten. Therefore set "mode" first and the part
537+ specific mode later.
538+
539+ Note: when writing to a file or buffer and when
540+ reading from a buffer NL mode is used by default.
541+
527542 *job-callback*
528543"callback": handler Callback for something to read on any part of the
529544 channel.
530- *job-out_cb*
545+ *job-out_cb* *out_cb*
531546"out_cb": handler Callback for when there is something to read on
532- stdout.
533- *job-err_cb*
547+ stdout. Only for when the channel uses pipes. When
548+ "out_cb" wasn't set the channel callback is used.
549+
550+ *job-err_cb* *err_cb*
534551"err_cb": handler Callback for when there is something to read on
535- stderr.
552+ stderr. Only for when the channel uses pipes. When
553+ "err_cb" wasn't set the channel callback is used.
536554 *job-close_cb*
537555"close_cb": handler Callback for when the channel is closed. Same as
538556 "close_cb" on ch_open().
@@ -542,6 +560,17 @@ See |job_setoptions()| and |ch_setoptions()|.
542560 Vim checks about every 10 seconds for jobs that ended.
543561 The callback can also be triggered by calling
544562 | job_status() | .
563+ *job-timeout*
564+ "timeout" The time to wait for a request when blocking, E.g.
565+ when using ch_evalexpr(). In milliseconds. The
566+ default is 2000 (2 seconds).
567+ *out_timeout* *err_timeout*
568+ "out_timeout" Timeout for stdout. Only when using pipes.
569+ "err_timeout" Timeout for stderr. Only when using pipes.
570+ Note: when setting "timeout" the part specific mode is
571+ overwritten. Therefore set "timeout" first and the
572+ part specific mode later.
573+
545574 *job-stoponexit*
546575"stoponexit": {signal} Send {signal} to the job when Vim exits. See
547576 | job_stop() | for possible values.
0 commit comments