1- *channel.txt* For Vim version 7.4. Last change: 2016 Feb 23
1+ *channel.txt* For Vim version 7.4. Last change: 2016 Feb 27
22
33
44 VIM REFERENCE MANUAL by Bram Moolenaar
@@ -74,7 +74,7 @@ In T1 you should see:
7474 === socket opened === ~
7575
7676You can now send a message to the server: >
77- echo ch_sendexpr (channel, 'hello!')
77+ echo ch_evalexpr (channel, 'hello!')
7878
7979 The message is received in T1 and a response is sent back to Vim.
8080You can see the raw messages in T1. What Vim sends is:
@@ -101,7 +101,7 @@ Instead of giving a callback with every send call, it can also be specified
101101when opening the channel: >
102102 call ch_close(channel)
103103 let channel = ch_open('localhost:8765', {'callback': "MyHandler"})
104- call ch_sendexpr(channel, 'hello!', {'callback': 0} )
104+ call ch_sendexpr(channel, 'hello!')
105105
106106==============================================================================
1071073. Opening a channel *channel-open*
@@ -130,6 +130,8 @@ Use |ch_status()| to see if the channel could be opened.
130130 overwritten. Therefore set "mode" first and the part specific
131131 mode later.
132132
133+ Note: when writing to a file or buffer NL mode is always used.
134+
133135 *channel-callback*
134136"callback" A function that is called when a message is received that is
135137 not handled otherwise. It gets two arguments: the channel
@@ -169,7 +171,7 @@ Use |ch_status()| to see if the channel could be opened.
169171 msec at least.
170172
171173"timeout" The time to wait for a request when blocking, E.g. when using
172- ch_sendexpr (). In milliseconds. The default is 2000 (2
174+ ch_evalexpr (). In milliseconds. The default is 2000 (2
173175 seconds).
174176 *out-timeout* *err-timeout*
175177"out-timeout" Timeout for stdout. Only when using pipes.
@@ -198,6 +200,7 @@ Once done with the channel, disconnect it like this: >
198200 When a socket is used this will close the socket for both directions. When
199201pipes are used (stdin/stdout/stderr) they are all closed. This might not be
200202what you want! Stopping the job with job_stop() might be better.
203+ All readahead is discarded, callbacks will no longer be invoked.
201204
202205When the channel can't be opened you will get an error message. There is a
203206difference between MS-Windows and Unix: On Unix when the port doesn't exist
@@ -211,15 +214,15 @@ If there is an error reading or writing a channel it will be closed.
2112144. Using a JSON or JS channel *channel-use*
212215
213216If mode is JSON then a message can be sent synchronously like this: >
214- let response = ch_sendexpr (channel, {expr})
217+ let response = ch_evalexpr (channel, {expr})
215218 This awaits a response from the other side.
216219
217220When mode is JS this works the same, except that the messages use
218221JavaScript encoding. See | js_encode() | for the difference.
219222
220223To send a message, without handling a response or letting the channel callback
221224handle the response: >
222- call ch_sendexpr(channel, {expr}, {'callback': 0} )
225+ call ch_sendexpr(channel, {expr})
223226
224227 To send a message and letting the response handled by a specific function,
225228asynchronously: >
@@ -260,8 +263,9 @@ On read error or ch_close(), when using a socket, the string "DETACH" is sent,
260263if still possible. The channel will then be inactive. For a JSON and JS mode
261264channel quotes are used around DETACH, otherwise there are no quotes.
262265
263- It is also possible to use ch_sendraw() on a JSON or JS channel. The caller
264- is then completely responsible for correct encoding and decoding.
266+ It is also possible to use ch_sendraw() and ch_evalraw() on a JSON or JS
267+ channel. The caller is then completely responsible for correct encoding and
268+ decoding.
265269
266270==============================================================================
2672715. Channel commands *channel-commands*
@@ -327,7 +331,7 @@ It will send back the result of the expression:
327331 [-2, "last line"] ~
328332The format is:
329333 [{number} , {result} ]
330- *E915*
334+
331335Here {number} is the same as what was in the request. Use a negative number
332336to avoid confusion with message that Vim sends. Use a different number on
333337every request to be able to match the request with the response.
@@ -360,7 +364,7 @@ Leave out the fourth argument if no response is to be sent:
3603646. Using a RAW or NL channel *channel-raw*
361365
362366If mode is RAW or NL then a message can be send like this: >
363- let response = ch_sendraw (channel, {string})
367+ let response = ch_evalraw (channel, {string})
364368
365369 The {string} is sent as-is. The response will be what can be read from the
366370channel right away. Since Vim doesn't know how to recognize the end of the
@@ -374,18 +378,18 @@ first NL. This can also be just the NL for an empty response.
374378If no NL was read before the channel timeout an empty string is returned.
375379
376380To send a message, without expecting a response: >
377- call ch_sendraw(channel, {string}, 0 )
381+ call ch_sendraw(channel, {string})
378382 The process can send back a response, the channel handler will be called with
379383it.
380384
381385To send a message and letting the response handled by a specific function,
382386asynchronously: >
383- call ch_sendraw(channel, {string}, {callback})
387+ call ch_sendraw(channel, {string}, {' callback': 'MyHandler' })
384388
385389 This {string} can also be JSON, use | json_encode() | to create it and
386390| json_decode() | to handle a received JSON message.
387391
388- It is not possible to use | ch_sendexpr() | on a raw channel.
392+ It is not possible to use | ch_evalexpr() | or | ch_sendexpr() | on a raw channel.
389393
390394==============================================================================
3913957. More channel functions *channel-more*
397401 "closed" The channel was closed.
398402
399403TODO:
400- To objain the job associated with a channel: ch_getjob(channel)
404+ To obtain the job associated with a channel: ch_getjob(channel)
401405
402406To read one message from a channel: >
403407 let output = ch_read(channel)
@@ -444,14 +448,17 @@ If you want to handle both stderr and stdout with one handler use the
444448"callback" option: >
445449 let job = job_start(command, {"callback": "MyHandler"})
446450
447- You can send a message to the command with ch_sendraw (). If the channel is in
448- JSON or JS mode you can use ch_sendexpr ().
451+ You can send a message to the command with ch_evalraw (). If the channel is in
452+ JSON or JS mode you can use ch_evalexpr ().
449453
450454There are several options you can use, see | job-options | .
455+ For example, to start a job and write its output in buffer "dummy": >
456+ let logjob = job_start("tail -f /tmp/log",
457+ \ {'out-io': 'buffer', 'out-name': 'dummy'})
458+ sbuf dummy
451459
452460 TODO:
453461To run a job and read its output once it is done: >
454-
455462 let job = job_start({command}, {'exit-cb': 'MyHandler'})
456463 func MyHandler(job, status)
457464 let channel = job_getchannel()
@@ -508,7 +515,7 @@ See |job_setoptions()| and |ch_setoptions()|.
508515 *job-err-cb*
509516"err-cb": handler Callback for when there is something to read on
510517 stderr.
511- TODO: *job-close-cb*
518+ *job-close-cb*
512519"close-cb": handler Callback for when the channel is closed. Same as
513520 "close-cb" on ch_open().
514521 *job-exit-cb*
@@ -527,28 +534,47 @@ TODO: *job-term*
527534"term": "open" Start a terminal and connect the job
528535 stdin/stdout/stderr to it.
529536
530- TODO: *job-in-io*
531- "in-io": "null" disconnect stdin
537+ *job-in-io*
538+ "in-io": "null" disconnect stdin TODO
532539"in-io": "pipe" stdin is connected to the channel (default)
533- "in-io": "file" stdin reads from a file
534- "in-file": "/path/file" the file to read from
540+ "in-io": "file" stdin reads from a file TODO
541+ "in-io": "buffer" stdin reads from a buffer TODO
542+ "in-name": "/path/file" the name of he file or buffer to read from
543+ "in-buf": number the number of the buffer to read from TODO
535544
536- TODO: *job-out-io*
537- "out-io": "null" disconnect stdout
545+ *job-out-io*
546+ "out-io": "null" disconnect stdout TODO
538547"out-io": "pipe" stdout is connected to the channel (default)
539- "out-io": "file" stdout writes to a file
540- "out-file": "/path/file" the file to write to
548+ "out-io": "file" stdout writes to a file TODO
541549"out-io": "buffer" stdout appends to a buffer
542- "out-buffer": "name" buffer to append to
543-
544- TODO: *job-err-io*
545- "err-io": "out" same type as stdout (default)
546- "err-io": "null" disconnect stderr
547- "err-io": "pipe" stderr is connected to the channel
548- "err-io": "file" stderr writes to a file
549- "err-file": "/path/file" the file to write to
550- "err-io": "buffer" stderr appends to a buffer
551- "err-buffer": "name" buffer to append to
550+ "out-name": "/path/file" the name of the file or buffer to write to
551+ "out-buf": number the number of the buffer to write to TODO
552+
553+ *job-err-io*
554+ "err-io": "out" same as stdout TODO
555+ "err-io": "null" disconnect stderr TODO
556+ "err-io": "pipe" stderr is connected to the channel (default)
557+ "err-io": "file" stderr writes to a file TODO
558+ "err-io": "buffer" stderr appends to a buffer TODO
559+ "err-name": "/path/file" the name of the file or buffer to write to
560+ "err-buf": number the number of the buffer to write to TODO
561+
562+ When the IO mode is "buffer" and there is a callback, the text is appended to
563+ the buffer before invoking the callback.
564+
565+ The name of the buffer is compared the full name of existing buffers. If
566+ there is a match that buffer is used. Otherwise a new buffer is created.
567+ Use an empty name to always create a new buffer. | ch_getbufnr() | can then be
568+ used to get the buffer number.
569+
570+ For a new buffer 'buftype' is set to "nofile" and 'bufhidden' to "hide". If
571+ you prefer other settings, create the buffer first and pass the buffer number.
572+
573+ When the buffer written to is displayed in a window and the cursor is in the
574+ first column of the last line, the cursor will be moved to the newly added
575+ line and the window is scrolled up to show the cursor if needed.
576+
577+ Undo is synced for every added line.
552578
553579==============================================================================
55458011. Controlling a job *job-control*
0 commit comments