Mercurial > vim
comparison runtime/doc/channel.txt @ 9041:34c45ee4210d
commit https://github.com/vim/vim/commit/06481427005a9dae39721087df94855f7d4d1feb
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Apr 30 15:13:38 2016 +0200
Update runtime files.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 30 Apr 2016 15:15:06 +0200 |
parents | 0bdeaf7092bc |
children | 9305a1251e51 |
comparison
equal
deleted
inserted
replaced
9040:c3ba708cfa09 | 9041:34c45ee4210d |
---|---|
1 *channel.txt* For Vim version 7.4. Last change: 2016 Mar 28 | 1 *channel.txt* For Vim version 7.4. Last change: 2016 Apr 26 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
394 | 394 |
395 To obtain the status of a channel: ch_status(channel). The possible results | 395 To obtain the status of a channel: ch_status(channel). The possible results |
396 are: | 396 are: |
397 "fail" Failed to open the channel. | 397 "fail" Failed to open the channel. |
398 "open" The channel can be used. | 398 "open" The channel can be used. |
399 "buffered" The channel was closed but there is data to read. | |
399 "closed" The channel was closed. | 400 "closed" The channel was closed. |
400 | 401 |
401 To obtain the job associated with a channel: ch_getjob(channel) | 402 To obtain the job associated with a channel: ch_getjob(channel) |
402 | 403 |
403 To read one message from a channel: > | 404 To read one message from a channel: > |
449 The function will be called with the channel and a message. You would define | 450 The function will be called with the channel and a message. You would define |
450 it like this: > | 451 it like this: > |
451 func MyHandler(channel, msg) | 452 func MyHandler(channel, msg) |
452 | 453 |
453 Without the handler you need to read the output with |ch_read()| or | 454 Without the handler you need to read the output with |ch_read()| or |
454 |ch_readraw()|. | 455 |ch_readraw()|. You can do this in the close callback, see |read-in-close-cb|. |
455 | 456 |
456 The handler defined for "out_cb" will not receive stderr. If you want to | 457 The handler defined for "out_cb" will not receive stderr. If you want to |
457 handle that separately, add an "err_cb" handler: > | 458 handle that separately, add an "err_cb" handler: > |
458 let job = job_start(command, {"out_cb": "MyHandler", | 459 let job = job_start(command, {"out_cb": "MyHandler", |
459 \ "err_cb": "ErrHandler"}) | 460 \ "err_cb": "ErrHandler"}) |
487 | 488 |
488 A special mode is when "in_top" is set to zero and "in_bot" is not set: Every | 489 A special mode is when "in_top" is set to zero and "in_bot" is not set: Every |
489 time a line is added to the buffer, the last-but-one line will be send to the | 490 time a line is added to the buffer, the last-but-one line will be send to the |
490 job stdin. This allows for editing the last line and sending it when pressing | 491 job stdin. This allows for editing the last line and sending it when pressing |
491 Enter. | 492 Enter. |
493 | |
494 | |
495 Reading job output in the close callback ~ | |
496 *read-in-close-cb* | |
497 If the job can take some time and you don't need intermediate results, you can | |
498 add a close callback and read the output there: > | |
499 | |
500 func! CloseHandler(channel) | |
501 while ch_status(a:channel) == 'buffered' | |
502 echomsg ch_read(a:channel) | |
503 endwhile | |
504 endfunc | |
505 let job = job_start(command, {'close_cb': 'CloseHandler'}) | |
506 | |
507 You will want to do something more useful than "echomsg". | |
492 | 508 |
493 ============================================================================== | 509 ============================================================================== |
494 9. Starting a job without a channel *job-start-nochannel* | 510 9. Starting a job without a channel *job-start-nochannel* |
495 | 511 |
496 To start another process without creating a channel: > | 512 To start another process without creating a channel: > |