Mercurial > vim
comparison runtime/doc/channel.txt @ 17831:4ab97fdf7ff7 v8.1.1912
patch 8.1.1912: more functions can be used as methods
Commit: https://github.com/vim/vim/commit/570497ac409ad448574bb6210cb9c6e573483759
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Aug 22 22:55:13 2019 +0200
patch 8.1.1912: more functions can be used as methods
Problem: More functions can be used as methods.
Solution: Make channel and job functions usable as a method.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 22 Aug 2019 23:00:03 +0200 |
parents | 2704c4e3e20a |
children | 8ac85adee561 |
comparison
equal
deleted
inserted
replaced
17830:e8805fbb60a3 | 17831:4ab97fdf7ff7 |
---|---|
1 *channel.txt* For Vim version 8.1. Last change: 2019 Jul 28 | 1 *channel.txt* For Vim version 8.1. Last change: 2019 Aug 22 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
472 e.g. from a timer. | 472 e.g. from a timer. |
473 | 473 |
474 Note that messages are dropped when the channel does not have | 474 Note that messages are dropped when the channel does not have |
475 a callback. Add a close callback to avoid that. | 475 a callback. Add a close callback to avoid that. |
476 | 476 |
477 Can also be used as a |method|: > | |
478 GetChannel()->ch_canread() | |
477 | 479 |
478 ch_close({handle}) *ch_close()* | 480 ch_close({handle}) *ch_close()* |
479 Close {handle}. See |channel-close|. | 481 Close {handle}. See |channel-close|. |
480 {handle} can be a Channel or a Job that has a Channel. | 482 {handle} can be a Channel or a Job that has a Channel. |
481 A close callback is not invoked. | 483 A close callback is not invoked. |
482 | 484 |
485 Can also be used as a |method|: > | |
486 GetChannel()->ch_close() | |
483 | 487 |
484 ch_close_in({handle}) *ch_close_in()* | 488 ch_close_in({handle}) *ch_close_in()* |
485 Close the "in" part of {handle}. See |channel-close-in|. | 489 Close the "in" part of {handle}. See |channel-close-in|. |
486 {handle} can be a Channel or a Job that has a Channel. | 490 {handle} can be a Channel or a Job that has a Channel. |
487 A close callback is not invoked. | 491 A close callback is not invoked. |
492 | |
493 Can also be used as a |method|: > | |
494 GetChannel()->ch_close_in() | |
488 | 495 |
489 | 496 |
490 ch_evalexpr({handle}, {expr} [, {options}]) *ch_evalexpr()* | 497 ch_evalexpr({handle}, {expr} [, {options}]) *ch_evalexpr()* |
491 Send {expr} over {handle}. The {expr} is encoded | 498 Send {expr} over {handle}. The {expr} is encoded |
492 according to the type of channel. The function cannot be used | 499 according to the type of channel. The function cannot be used |
499 | 506 |
500 ch_evalexpr() waits for a response and returns the decoded | 507 ch_evalexpr() waits for a response and returns the decoded |
501 expression. When there is an error or timeout it returns an | 508 expression. When there is an error or timeout it returns an |
502 empty string. | 509 empty string. |
503 | 510 |
511 Can also be used as a |method|: > | |
512 GetChannel()->ch_evalexpr(expr) | |
513 | |
504 | 514 |
505 ch_evalraw({handle}, {string} [, {options}]) *ch_evalraw()* | 515 ch_evalraw({handle}, {string} [, {options}]) *ch_evalraw()* |
506 Send {string} over {handle}. | 516 Send {string} over {handle}. |
507 {handle} can be a Channel or a Job that has a Channel. | 517 {handle} can be a Channel or a Job that has a Channel. |
508 | 518 |
514 Note that Vim does not know when the text received on a raw | 524 Note that Vim does not know when the text received on a raw |
515 channel is complete, it may only return the first part and you | 525 channel is complete, it may only return the first part and you |
516 need to use |ch_readraw()| to fetch the rest. | 526 need to use |ch_readraw()| to fetch the rest. |
517 See |channel-use|. | 527 See |channel-use|. |
518 | 528 |
529 Can also be used as a |method|: > | |
530 GetChannel()->ch_evalraw(rawstring) | |
519 | 531 |
520 ch_getbufnr({handle}, {what}) *ch_getbufnr()* | 532 ch_getbufnr({handle}, {what}) *ch_getbufnr()* |
521 Get the buffer number that {handle} is using for {what}. | 533 Get the buffer number that {handle} is using for {what}. |
522 {handle} can be a Channel or a Job that has a Channel. | 534 {handle} can be a Channel or a Job that has a Channel. |
523 {what} can be "err" for stderr, "out" for stdout or empty for | 535 {what} can be "err" for stderr, "out" for stdout or empty for |
524 socket output. | 536 socket output. |
525 Returns -1 when there is no buffer. | 537 Returns -1 when there is no buffer. |
526 | 538 |
539 Can also be used as a |method|: > | |
540 GetChannel()->ch_getbufnr(what) | |
527 | 541 |
528 ch_getjob({channel}) *ch_getjob()* | 542 ch_getjob({channel}) *ch_getjob()* |
529 Get the Job associated with {channel}. | 543 Get the Job associated with {channel}. |
530 If there is no job calling |job_status()| on the returned Job | 544 If there is no job calling |job_status()| on the returned Job |
531 will result in "fail". | 545 will result in "fail". |
546 | |
547 Can also be used as a |method|: > | |
548 GetChannel()->ch_getjob() | |
532 | 549 |
533 | 550 |
534 ch_info({handle}) *ch_info()* | 551 ch_info({handle}) *ch_info()* |
535 Returns a Dictionary with information about {handle}. The | 552 Returns a Dictionary with information about {handle}. The |
536 items are: | 553 items are: |
556 "in_status" "open" or "closed" | 573 "in_status" "open" or "closed" |
557 "in_mode" "NL", "RAW", "JSON" or "JS" | 574 "in_mode" "NL", "RAW", "JSON" or "JS" |
558 "in_io" "null", "pipe", "file" or "buffer" | 575 "in_io" "null", "pipe", "file" or "buffer" |
559 "in_timeout" timeout in msec | 576 "in_timeout" timeout in msec |
560 | 577 |
578 Can also be used as a |method|: > | |
579 GetChannel()->ch_info() | |
580 | |
561 | 581 |
562 ch_log({msg} [, {handle}]) *ch_log()* | 582 ch_log({msg} [, {handle}]) *ch_log()* |
563 Write {msg} in the channel log file, if it was opened with | 583 Write {msg} in the channel log file, if it was opened with |
564 |ch_logfile()|. | 584 |ch_logfile()|. |
565 When {handle} is passed the channel number is used for the | 585 When {handle} is passed the channel number is used for the |
566 message. | 586 message. |
567 {handle} can be a Channel or a Job that has a Channel. The | 587 {handle} can be a Channel or a Job that has a Channel. The |
568 Channel must be open for the channel number to be used. | 588 Channel must be open for the channel number to be used. |
569 | 589 |
590 Can also be used as a |method|: > | |
591 'did something'->ch_log() | |
592 | |
570 | 593 |
571 ch_logfile({fname} [, {mode}]) *ch_logfile()* | 594 ch_logfile({fname} [, {mode}]) *ch_logfile()* |
572 Start logging channel activity to {fname}. | 595 Start logging channel activity to {fname}. |
573 When {fname} is an empty string: stop logging. | 596 When {fname} is an empty string: stop logging. |
574 | 597 |
582 This function is not available in the |sandbox|. | 605 This function is not available in the |sandbox|. |
583 NOTE: the channel communication is stored in the file, be | 606 NOTE: the channel communication is stored in the file, be |
584 aware that this may contain confidential and privacy sensitive | 607 aware that this may contain confidential and privacy sensitive |
585 information, e.g. a password you type in a terminal window. | 608 information, e.g. a password you type in a terminal window. |
586 | 609 |
610 Can also be used as a |method|: > | |
611 'logfile'->ch_logfile('w') | |
612 | |
587 | 613 |
588 ch_open({address} [, {options}]) *ch_open()* | 614 ch_open({address} [, {options}]) *ch_open()* |
589 Open a channel to {address}. See |channel|. | 615 Open a channel to {address}. See |channel|. |
590 Returns a Channel. Use |ch_status()| to check for failure. | 616 Returns a Channel. Use |ch_status()| to check for failure. |
591 | 617 |
592 {address} has the form "hostname:port", e.g., | 618 {address} has the form "hostname:port", e.g., |
593 "localhost:8765". | 619 "localhost:8765". |
594 | 620 |
595 If {options} is given it must be a |Dictionary|. | 621 If {options} is given it must be a |Dictionary|. |
596 See |channel-open-options|. | 622 See |channel-open-options|. |
623 | |
624 Can also be used as a |method|: > | |
625 GetAddress()->ch_open() | |
597 | 626 |
598 | 627 |
599 ch_read({handle} [, {options}]) *ch_read()* | 628 ch_read({handle} [, {options}]) *ch_read()* |
600 Read from {handle} and return the received message. | 629 Read from {handle} and return the received message. |
601 {handle} can be a Channel or a Job that has a Channel. | 630 {handle} can be a Channel or a Job that has a Channel. |
602 For a NL channel this waits for a NL to arrive, except when | 631 For a NL channel this waits for a NL to arrive, except when |
603 there is nothing more to read (channel was closed). | 632 there is nothing more to read (channel was closed). |
604 See |channel-more|. | 633 See |channel-more|. |
605 | 634 |
635 Can also be used as a |method|: > | |
636 GetChannel()->ch_read() | |
637 | |
606 | 638 |
607 ch_readblob({handle} [, {options}]) *ch_readblob()* | 639 ch_readblob({handle} [, {options}]) *ch_readblob()* |
608 Like ch_read() but reads binary data and returns a |Blob|. | 640 Like ch_read() but reads binary data and returns a |Blob|. |
609 See |channel-more|. | 641 See |channel-more|. |
642 | |
643 Can also be used as a |method|: > | |
644 GetChannel()->ch_readblob() | |
610 | 645 |
611 | 646 |
612 ch_readraw({handle} [, {options}]) *ch_readraw()* | 647 ch_readraw({handle} [, {options}]) *ch_readraw()* |
613 Like ch_read() but for a JS and JSON channel does not decode | 648 Like ch_read() but for a JS and JSON channel does not decode |
614 the message. For a NL channel it does not block waiting for | 649 the message. For a NL channel it does not block waiting for |
615 the NL to arrive, but otherwise works like ch_read(). | 650 the NL to arrive, but otherwise works like ch_read(). |
616 See |channel-more|. | 651 See |channel-more|. |
652 | |
653 Can also be used as a |method|: > | |
654 GetChannel()->ch_readraw() | |
617 | 655 |
618 | 656 |
619 ch_sendexpr({handle}, {expr} [, {options}]) *ch_sendexpr()* | 657 ch_sendexpr({handle}, {expr} [, {options}]) *ch_sendexpr()* |
620 Send {expr} over {handle}. The {expr} is encoded | 658 Send {expr} over {handle}. The {expr} is encoded |
621 according to the type of channel. The function cannot be used | 659 according to the type of channel. The function cannot be used |
622 with a raw channel. | 660 with a raw channel. |
623 See |channel-use|. *E912* | 661 See |channel-use|. *E912* |
624 {handle} can be a Channel or a Job that has a Channel. | 662 {handle} can be a Channel or a Job that has a Channel. |
663 | |
664 Can also be used as a |method|: > | |
665 GetChannel()->ch_sendexpr(expr) | |
625 | 666 |
626 | 667 |
627 ch_sendraw({handle}, {expr} [, {options}]) *ch_sendraw()* | 668 ch_sendraw({handle}, {expr} [, {options}]) *ch_sendraw()* |
628 Send |String| or |Blob| {expr} over {handle}. | 669 Send |String| or |Blob| {expr} over {handle}. |
629 Works like |ch_sendexpr()|, but does not encode the request or | 670 Works like |ch_sendexpr()|, but does not encode the request or |
631 correct contents. Also does not add a newline for a channel | 672 correct contents. Also does not add a newline for a channel |
632 in NL mode, the caller must do that. The NL in the response | 673 in NL mode, the caller must do that. The NL in the response |
633 is removed. | 674 is removed. |
634 See |channel-use|. | 675 See |channel-use|. |
635 | 676 |
677 Can also be used as a |method|: > | |
678 GetChannel()->ch_sendraw(rawexpr) | |
679 | |
636 | 680 |
637 ch_setoptions({handle}, {options}) *ch_setoptions()* | 681 ch_setoptions({handle}, {options}) *ch_setoptions()* |
638 Set options on {handle}: | 682 Set options on {handle}: |
639 "callback" the channel callback | 683 "callback" the channel callback |
640 "timeout" default read timeout in msec | 684 "timeout" default read timeout in msec |
645 Note that changing the mode may cause queued messages to be | 689 Note that changing the mode may cause queued messages to be |
646 lost. | 690 lost. |
647 | 691 |
648 These options cannot be changed: | 692 These options cannot be changed: |
649 "waittime" only applies to |ch_open()| | 693 "waittime" only applies to |ch_open()| |
694 | |
695 Can also be used as a |method|: > | |
696 GetChannel()->ch_setoptions(options) | |
650 | 697 |
651 | 698 |
652 ch_status({handle} [, {options}]) *ch_status()* | 699 ch_status({handle} [, {options}]) *ch_status()* |
653 Return the status of {handle}: | 700 Return the status of {handle}: |
654 "fail" failed to open the channel | 701 "fail" failed to open the channel |
662 If {options} is given it can contain a "part" entry to specify | 709 If {options} is given it can contain a "part" entry to specify |
663 the part of the channel to return the status for: "out" or | 710 the part of the channel to return the status for: "out" or |
664 "err". For example, to get the error status: > | 711 "err". For example, to get the error status: > |
665 ch_status(job, {"part": "err"}) | 712 ch_status(job, {"part": "err"}) |
666 < | 713 < |
714 Can also be used as a |method|: > | |
715 GetChannel()->ch_status() | |
667 | 716 |
668 ============================================================================== | 717 ============================================================================== |
669 9. Starting a job with a channel *job-start* *job* | 718 9. Starting a job with a channel *job-start* *job* |
670 | 719 |
671 To start a job and open a channel for stdin/stdout/stderr: > | 720 To start a job and open a channel for stdin/stdout/stderr: > |
790 job_getchannel({job}) *job_getchannel()* | 839 job_getchannel({job}) *job_getchannel()* |
791 Get the channel handle that {job} is using. | 840 Get the channel handle that {job} is using. |
792 To check if the job has no channel: > | 841 To check if the job has no channel: > |
793 if string(job_getchannel()) == 'channel fail' | 842 if string(job_getchannel()) == 'channel fail' |
794 < | 843 < |
844 Can also be used as a |method|: > | |
845 GetJob()->job_getchannel() | |
795 | 846 |
796 job_info([{job}]) *job_info()* | 847 job_info([{job}]) *job_info()* |
797 Returns a Dictionary with information about {job}: | 848 Returns a Dictionary with information about {job}: |
798 "status" what |job_status()| returns | 849 "status" what |job_status()| returns |
799 "channel" what |job_getchannel()| returns | 850 "channel" what |job_getchannel()| returns |
815 Values are "winpty" or "conpty". | 866 Values are "winpty" or "conpty". |
816 See 'termwintype'. | 867 See 'termwintype'. |
817 | 868 |
818 Without any arguments, returns a List with all Job objects. | 869 Without any arguments, returns a List with all Job objects. |
819 | 870 |
871 Can also be used as a |method|: > | |
872 GetJob()->job_info() | |
873 | |
820 | 874 |
821 job_setoptions({job}, {options}) *job_setoptions()* | 875 job_setoptions({job}, {options}) *job_setoptions()* |
822 Change options for {job}. Supported are: | 876 Change options for {job}. Supported are: |
823 "stoponexit" |job-stoponexit| | 877 "stoponexit" |job-stoponexit| |
824 "exit_cb" |job-exit_cb| | 878 "exit_cb" |job-exit_cb| |
879 | |
880 Can also be used as a |method|: > | |
881 GetJob()->job_setoptions(options) | |
825 | 882 |
826 | 883 |
827 job_start({command} [, {options}]) *job_start()* | 884 job_start({command} [, {options}]) *job_start()* |
828 Start a job and return a Job object. Unlike |system()| and | 885 Start a job and return a Job object. Unlike |system()| and |
829 |:!cmd| this does not wait for the job to finish. | 886 |:!cmd| this does not wait for the job to finish. |
879 let s:myjob = job_start('my-command') | 936 let s:myjob = job_start('my-command') |
880 < | 937 < |
881 {options} must be a Dictionary. It can contain many optional | 938 {options} must be a Dictionary. It can contain many optional |
882 items, see |job-options|. | 939 items, see |job-options|. |
883 | 940 |
941 Can also be used as a |method|: > | |
942 BuildCommand()->job_start() | |
943 | |
884 | 944 |
885 job_status({job}) *job_status()* *E916* | 945 job_status({job}) *job_status()* *E916* |
886 Returns a String with the status of {job}: | 946 Returns a String with the status of {job}: |
887 "run" job is running | 947 "run" job is running |
888 "fail" job failed to start | 948 "fail" job failed to start |
894 | 954 |
895 If an exit callback was set with the "exit_cb" option and the | 955 If an exit callback was set with the "exit_cb" option and the |
896 job is now detected to be "dead" the callback will be invoked. | 956 job is now detected to be "dead" the callback will be invoked. |
897 | 957 |
898 For more information see |job_info()|. | 958 For more information see |job_info()|. |
959 | |
960 Can also be used as a |method|: > | |
961 GetJob()->job_status() | |
899 | 962 |
900 | 963 |
901 job_stop({job} [, {how}]) *job_stop()* | 964 job_stop({job} [, {how}]) *job_stop()* |
902 Stop the {job}. This can also be used to signal the job. | 965 Stop the {job}. This can also be used to signal the job. |
903 | 966 |
937 sent. This is to avoid to stop the wrong job (esp. on Unix, | 1000 sent. This is to avoid to stop the wrong job (esp. on Unix, |
938 where process numbers are recycled). | 1001 where process numbers are recycled). |
939 | 1002 |
940 When using "kill" Vim will assume the job will die and close | 1003 When using "kill" Vim will assume the job will die and close |
941 the channel. | 1004 the channel. |
1005 | |
1006 Can also be used as a |method|: > | |
1007 GetJob()->job_stop() | |
942 | 1008 |
943 | 1009 |
944 ============================================================================== | 1010 ============================================================================== |
945 12. Job options *job-options* | 1011 12. Job options *job-options* |
946 | 1012 |