1- *channel.txt* For Vim version 7.4. Last change: 2016 Feb 27
1+ *channel.txt* For Vim version 7.4. Last change: 2016 Mar 03
22
33
44 VIM REFERENCE MANUAL by Bram Moolenaar
@@ -103,6 +103,11 @@ when opening the channel: >
103103 let channel = ch_open('localhost:8765', {'callback': "MyHandler"})
104104 call ch_sendexpr(channel, 'hello!')
105105
106+ When trying out channels it's useful to see what is going on. You can tell
107+ Vim to write lines in log file: >
108+ call ch_logfile('channellog', 'w')
109+ See | ch_logfile() | .
110+
106111==============================================================================
1071123. Opening a channel *channel-open*
108113
@@ -130,7 +135,8 @@ Use |ch_status()| to see if the channel could be opened.
130135 overwritten. Therefore set "mode" first and the part specific
131136 mode later.
132137
133- Note: when writing to a file or buffer NL mode is always used.
138+ Note: when writing to a file or buffer and when reading from a
139+ buffer NL mode is used by default.
134140
135141 *channel-callback*
136142"callback" A function that is called when a message is received that is
@@ -191,6 +197,10 @@ For example, the handler can be added or changed: >
191197 call ch_setoptions(channel, {'callback': callback})
192198 When "callback" is empty (zero or an empty string) the handler is removed.
193199
200+ After a callback has been invoked Vim will update the screen and put the
201+ cursor back where it belongs. Thus the callback should not need to do
202+ `:redraw ` .
203+
194204The timeout can be changed: >
195205 call ch_setoptions(channel, {'timeout': msec})
196206<
@@ -259,9 +269,9 @@ message, it must use the number zero:
259269Then channel handler will then get {response} converted to Vim types. If the
260270channel does not have a handler the message is dropped.
261271
262- On read error or ch_close(), when using a socket, the string "DETACH" is sent,
263- if still possible. The channel will then be inactive. For a JSON and JS mode
264- channel quotes are used around DETACH, otherwise there are no quotes .
272+ On read error or ch_close(), when using a socket with RAW or NL mode, the
273+ string "DETACH\n" is sent, if still possible. The channel will then be
274+ inactive .
265275
266276It is also possible to use ch_sendraw() and ch_evalraw() on a JSON or JS
267277channel. The caller is then completely responsible for correct encoding and
@@ -457,6 +467,22 @@ For example, to start a job and write its output in buffer "dummy": >
457467 \ {'out-io': 'buffer', 'out-name': 'dummy'})
458468 sbuf dummy
459469
470+ To run a job that reads from a buffer: >
471+ let job = job_start({command},
472+ \ {'in-io': 'buffer', 'in-name': 'mybuffer'})
473+ <
474+ *E915* *E918*
475+ The buffer is found by name, similar to | bufnr() | . The buffer must exist and
476+ be loaded when job_start() is called.
477+
478+ By default this reads the whole buffer. This can be changed with the "in-top"
479+ and "in-bot" options.
480+
481+ TODO
482+ A special mode is when "in-top" is set to zero and "in-bot" is not set: The
483+ last-but-one line will be send to the job stdin. This allows for editing the
484+ last line and sending it when pressing Enter.
485+
460486TODO:
461487To run a job and read its output once it is done: >
462488 let job = job_start({command}, {'exit-cb': 'MyHandler'})
@@ -470,7 +496,8 @@ To run a job and read its output once it is done: >
4704969. Starting a job without a channel *job-start-nochannel*
471497
472498To start another process without creating a channel: >
473- let job = job_start(command, {"in-io": "null", "out-io": "null"})
499+ let job = job_start(command,
500+ \ {"in-io": "null", "out-io": "null", "err-io": "null"})
474501
475502 This starts {command} in the background, Vim does not wait for it to finish.
476503
@@ -538,7 +565,9 @@ TODO: *job-term*
538565"in-io": "null" disconnect stdin TODO
539566"in-io": "pipe" stdin is connected to the channel (default)
540567"in-io": "file" stdin reads from a file TODO
541- "in-io": "buffer" stdin reads from a buffer TODO
568+ "in-io": "buffer" stdin reads from a buffer
569+ "in-top": number when using "buffer": first line to send (default: 1)
570+ "in-bot": number when using "buffer": last line to send (default: last)
542571"in-name": "/path/file" the name of he file or buffer to read from
543572"in-buf": number the number of the buffer to read from TODO
544573
@@ -551,7 +580,7 @@ TODO: *job-term*
551580"out-buf": number the number of the buffer to write to TODO
552581
553582 *job-err-io*
554- "err-io": "out" same as stdout TODO
583+ "err-io": "out" stderr messages to go to stdout
555584"err-io": "null" disconnect stderr TODO
556585"err-io": "pipe" stderr is connected to the channel (default)
557586"err-io": "file" stderr writes to a file TODO
@@ -562,6 +591,10 @@ TODO: *job-term*
562591When the IO mode is "buffer" and there is a callback, the text is appended to
563592the buffer before invoking the callback.
564593
594+ When using JS or JSON mode with "buffer", only messages with zero or negative
595+ ID will be added to the buffer, after decoding + encoding. Messages with a
596+ positive number will be handled by a callback, commands are handled as usual.
597+
565598The name of the buffer is compared the full name of existing buffers. If
566599there is a match that buffer is used. Otherwise a new buffer is created.
567600Use an empty name to always create a new buffer. | ch_getbufnr() | can then be
0 commit comments