1- *channel.txt* For Vim version 7.4. Last change: 2016 Mar 06
1+ *channel.txt* For Vim version 7.4. Last change: 2016 Mar 12
22
33
44 VIM REFERENCE MANUAL by Bram Moolenaar
@@ -44,8 +44,8 @@ There are four main types of jobs:
44444. Running a filter, synchronously.
4545 Uses pipes.
4646
47- For when using sockets See | job-start | , | job-may- start | and | channel-open | .
48- For 2 and 3, one or more jobs using pipes, see | job-start | .
47+ For when using sockets See | job-start | , | job-start-nochannel | and
48+ | channel-open | . For 2 and 3, one or more jobs using pipes, see | job-start | .
4949For 4 use the ":{range} !cmd" command, see | filter | .
5050
5151Over the socket and pipes these protocols are available:
@@ -162,7 +162,7 @@ Use |ch_status()| to see if the channel could be opened.
162162 the channel uses pipes. When "err-cb" wasn't set the channel
163163 callback is used.
164164
165- TODO: *close-cb*
165+ *close-cb*
166166"close-cb" A function that is called when the channel gets closed, other
167167 than by calling ch_close(). It should be defined like this: >
168168 func MyCloseHandler(channel)
410410 "open" The channel can be used.
411411 "closed" The channel was closed.
412412
413- TODO:
414413To obtain the job associated with a channel: ch_getjob(channel)
415414
416415To read one message from a channel: >
@@ -486,15 +485,6 @@ time a line is added to the buffer, the last-but-one line will be send to the
486485job stdin. This allows for editing the last line and sending it when pressing
487486Enter.
488487
489- TODO:
490- To run a job and read its output once it is done: >
491- let job = job_start({command}, {'exit-cb': 'MyHandler'})
492- func MyHandler(job, status)
493- let channel = job_getchannel()
494- let output = ch_readall(channel)
495- " parse output
496- endfunc
497-
498488==============================================================================
4994899. Starting a job without a channel *job-start-nochannel*
500490
@@ -504,28 +494,23 @@ To start another process without creating a channel: >
504494
505495 This starts {command} in the background, Vim does not wait for it to finish.
506496
507- TODO:
508497When Vim sees that neither stdin, stdout or stderr are connected, no channel
509498will be created. Often you will want to include redirection in the command to
510499avoid it getting stuck.
511500
512501There are several options you can use, see | job-options | .
513502
514- TODO: *job-may-start*
515- To start a job only when connecting to an address does not work use
516- job_maystart('command' , {address} , {options} ), For Example: >
517- let job = job_maystart(command, address, {"waittime": 1000})
518- let channel = job_gethandle(job)
519-
520- This comes down to: >
503+ *job-start-if-needed*
504+ To start a job only when connecting to an address does not work, do something
505+ like this: >
521506 let channel = ch_open(address, {"waittime": 0})
522507 if ch_status(channel) == "fail"
523508 let job = job_start(command)
524509 let channel = ch_open(address, {"waittime": 1000})
525- call job_sethandle(channel)
526510 endif
527- Note that the specified waittime applies to when the job has been started.
528- This gives the job some time to make the port available.
511+
512+ Note that the waittime for ch_open() gives the job one second to make the port
513+ available.
529514
530515==============================================================================
53151610. Job options *job-options*
@@ -560,43 +545,54 @@ See |job_setoptions()| and |ch_setoptions()|.
560545"stoponexit": "" Do not stop the job when Vim exits.
561546 The default is "term".
562547
563- TODO: *job-term*
548+ *job-term*
564549"term": "open" Start a terminal and connect the job
565550 stdin/stdout/stderr to it.
551+ NOTE: Not implemented yet!
552+
553+ "channel": {channel} Use an existing channel instead of creating a new one.
554+ The parts of the channel that get used for the new job
555+ will be disconnected from what they were used before.
556+ If the channel was still use by another job this may
557+ cause I/O errors.
558+ Existing callbacks and other settings remain.
566559
567- *job-in-io*
568- "in-io": "null" disconnect stdin TODO
560+ *job-in-io* *in-top* *in-bot* *in-name* *in-buf *
561+ "in-io": "null" disconnect stdin (read from /dev/null)
569562"in-io": "pipe" stdin is connected to the channel (default)
570- "in-io": "file" stdin reads from a file TODO
563+ "in-io": "file" stdin reads from a file
571564"in-io": "buffer" stdin reads from a buffer
572565"in-top": number when using "buffer": first line to send (default: 1)
573566"in-bot": number when using "buffer": last line to send (default: last)
574567"in-name": "/path/file" the name of the file or buffer to read from
575- "in-buf": number the number of the buffer to read from TODO
568+ "in-buf": number the number of the buffer to read from
576569
577- *job-out-io*
578- "out-io": "null" disconnect stdout TODO
570+ *job-out-io* *out-name* *out-buf *
571+ "out-io": "null" disconnect stdout (goes to /dev/null)
579572"out-io": "pipe" stdout is connected to the channel (default)
580- "out-io": "file" stdout writes to a file TODO
573+ "out-io": "file" stdout writes to a file
581574"out-io": "buffer" stdout appends to a buffer
582575"out-name": "/path/file" the name of the file or buffer to write to
583- "out-buf": number the number of the buffer to write to TODO
576+ "out-buf": number the number of the buffer to write to
584577
585- *job-err-io*
578+ *job-err-io* *err-name* *err-buf *
586579"err-io": "out" stderr messages to go to stdout
587- "err-io": "null" disconnect stderr TODO
580+ "err-io": "null" disconnect stderr (goes to /dev/null)
588581"err-io": "pipe" stderr is connected to the channel (default)
589- "err-io": "file" stderr writes to a file TODO
590- "err-io": "buffer" stderr appends to a buffer TODO
582+ "err-io": "file" stderr writes to a file
583+ "err-io": "buffer" stderr appends to a buffer
591584"err-name": "/path/file" the name of the file or buffer to write to
592- "err-buf": number the number of the buffer to write to TODO
585+ "err-buf": number the number of the buffer to write to
586+
587+
588+ Writing to a buffer ~
593589
594590When the out-io or err-io mode is "buffer" and there is a callback, the text
595591is appended to the buffer before invoking the callback.
596592
597593When a buffer is used both for input and output, the output lines are put
598594above the last line, since the last line is what is written to the channel
599- input. Otherwise lines are appened below the last line.
595+ input. Otherwise lines are appended below the last line.
600596
601597When using JS or JSON mode with "buffer", only messages with zero or negative
602598ID will be added to the buffer, after decoding + encoding. Messages with a
@@ -616,6 +612,14 @@ line and the window is scrolled up to show the cursor if needed.
616612
617613Undo is synced for every added line.
618614
615+
616+ Writing to a file ~
617+
618+ The file is created with permissions 600 (read-write for the user, not
619+ accessible for others). Use | setfperm() | to change this.
620+
621+ If the file already exists it is truncated.
622+
619623==============================================================================
62062411. Controlling a job *job-control*
621625
0 commit comments