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
2
2
3
3
4
4
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -44,8 +44,8 @@ There are four main types of jobs:
44
44
4. Running a filter, synchronously.
45
45
Uses pipes.
46
46
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 | .
49
49
For 4 use the ":{range} !cmd" command, see | filter | .
50
50
51
51
Over the socket and pipes these protocols are available:
@@ -162,7 +162,7 @@ Use |ch_status()| to see if the channel could be opened.
162
162
the channel uses pipes. When "err-cb" wasn't set the channel
163
163
callback is used.
164
164
165
- TODO: *close-cb*
165
+ *close-cb*
166
166
"close-cb" A function that is called when the channel gets closed, other
167
167
than by calling ch_close(). It should be defined like this: >
168
168
func MyCloseHandler(channel)
410
410
"open" The channel can be used.
411
411
"closed" The channel was closed.
412
412
413
- TODO:
414
413
To obtain the job associated with a channel: ch_getjob(channel)
415
414
416
415
To 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
486
485
job stdin. This allows for editing the last line and sending it when pressing
487
486
Enter.
488
487
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
-
498
488
==============================================================================
499
489
9. Starting a job without a channel *job-start-nochannel*
500
490
@@ -504,28 +494,23 @@ To start another process without creating a channel: >
504
494
505
495
This starts {command} in the background, Vim does not wait for it to finish.
506
496
507
- TODO:
508
497
When Vim sees that neither stdin, stdout or stderr are connected, no channel
509
498
will be created. Often you will want to include redirection in the command to
510
499
avoid it getting stuck.
511
500
512
501
There are several options you can use, see | job-options | .
513
502
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: >
521
506
let channel = ch_open(address, {"waittime": 0})
522
507
if ch_status(channel) == "fail"
523
508
let job = job_start(command)
524
509
let channel = ch_open(address, {"waittime": 1000})
525
- call job_sethandle(channel)
526
510
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.
529
514
530
515
==============================================================================
531
516
10. Job options *job-options*
@@ -560,43 +545,54 @@ See |job_setoptions()| and |ch_setoptions()|.
560
545
"stoponexit": "" Do not stop the job when Vim exits.
561
546
The default is "term".
562
547
563
- TODO: *job-term*
548
+ *job-term*
564
549
"term": "open" Start a terminal and connect the job
565
550
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.
566
559
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)
569
562
"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
571
564
"in-io": "buffer" stdin reads from a buffer
572
565
"in-top": number when using "buffer": first line to send (default: 1)
573
566
"in-bot": number when using "buffer": last line to send (default: last)
574
567
"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
576
569
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)
579
572
"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
581
574
"out-io": "buffer" stdout appends to a buffer
582
575
"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
584
577
585
- *job-err-io*
578
+ *job-err-io* *err-name* *err-buf *
586
579
"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)
588
581
"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
591
584
"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 ~
593
589
594
590
When the out-io or err-io mode is "buffer" and there is a callback, the text
595
591
is appended to the buffer before invoking the callback.
596
592
597
593
When a buffer is used both for input and output, the output lines are put
598
594
above 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.
600
596
601
597
When using JS or JSON mode with "buffer", only messages with zero or negative
602
598
ID 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.
616
612
617
613
Undo is synced for every added line.
618
614
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
+
619
623
==============================================================================
620
624
11. Controlling a job *job-control*
621
625
0 commit comments