Skip to content

Commit 135a0b7

Browse files
authored
Merge pull request #300 from vim-jp/working_channel
Update channel from Vim 8.0 to 8.1
2 parents 155bd70 + 2487eb8 commit 135a0b7

File tree

2 files changed

+145
-32
lines changed

2 files changed

+145
-32
lines changed

doc/channel.jax

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*channel.txt* For Vim バージョン 8.0. Last change: 2016 Dec 02
1+
*channel.txt* For Vim バージョン 8.1. Last change: 2018 Apr 18
22

33

44
VIMリファレンスマニュアル by Bram Moolenaar
@@ -16,12 +16,13 @@ Netbeans インターフェイスもチャネルを使っています。|netbean
1616
3. チャネルを開く |channel-open|
1717
4. JSON、JS チャネルを使う |channel-use|
1818
5. チャネルコマンド |channel-commands|
19-
6. RAW、NL チャネルをつかう |channel-raw|
19+
6. RAW、NL チャネルを使う |channel-raw|
2020
7. その他のチャネル機能 |channel-more|
2121
8. チャネルでジョブを開始する |job-start|
2222
9. チャネルなしでジョブを開始する |job-start-nochannel|
2323
10. ジョブオプション |job-options|
2424
11. ジョブを制御する |job-control|
25+
12. プロンプトバッファを使う |prompt-buffer|
2526

2627
{Vi にはこれらの機能はありません}
2728
{Vim が |+channel| 機能付きでコンパイルされたときのみ有効}
@@ -490,6 +491,12 @@ JS または JSON チャネルの場合、これは1つのデコードされた
490491
ンを使用します: >
491492
let job = job_start(command, {"callback": "MyHandler"})
492493
494+
システムによっては、ジョブを開始するとVimをバックグラウンドに移動することがあ
495+
り、開始されたジョブはフォーカスを取得します。これを避けるには `foreground()`
496+
関数を使用してください。これは、早く呼び出されたとき、コールバックハンドラ内に
497+
置いたとき、またはジョブが開始した後にタイマーを使用して呼び出すときは、必ずし
498+
も機能しない場合があります。
499+
493500
ch_evalraw() でコマンドにメッセージを送ることができます。チャネルが JSON また
494501
は JS モードの場合、ch_evalexpr() を使用できます。
495502

@@ -513,9 +520,9 @@ ch_evalraw() でコマンドにメッセージを送ることができます。
513520
デフォルトでは、これはバッファ全体を読み込みます。これは "in_top" と "in_bot"
514521
オプションで変更できます。
515522

516-
特殊モードは、in_top が 0 に設定され、in_bot が設定されていない場合です。バッ
517-
ファに行が追加されるたびに、最後の 1 行がジョブ stdin に送信されます。これによ
518-
、最後の行を編集し、Enter を押したときに送信することができます。
523+
特殊モードは、"in_top" が 0 に設定され、"in_bot" が設定されていない場合です。
524+
バッファに行が追加されるたびに、最後の 1 行がジョブ stdin に送信されます。これ
525+
により、最後の行を編集し、Enter を押したときに送信することができます。
519526
*channel-close-in*
520527
特殊モードを使用しないときは、最後の行が書き込まれた後にパイプまたはソケットが
521528
閉じられます。これは、入力が終了した読み取り終了を知らせます。|ch_close_in()|
@@ -606,7 +613,7 @@ job_setoptions(job, {options}) を使用して、ジョブの開始後にいく
606613
"close_cb": handler チャネルが閉じられるときのコールバック。
607614
|ch_open()| の "close_cb" と同じです。|close_cb| 参照。
608615
*job-drop*
609-
"drop" メッセージをいつドロップするかを指定します。
616+
"drop": when メッセージをいつドロップするかを指定します。
610617
|ch_open()| の "drop" と同様(|channel-drop| 参照)。
611618
"auto" の場合、exit_cb は考慮されません。
612619
*job-exit_cb*
@@ -619,12 +626,12 @@ job_setoptions(job, {options}) を使用して、ジョブの開始後にいく
619626
データがバッファリングされ、プロセスが終了した後もコー
620627
ルバックが呼び出されることに注意してください。
621628
*job-timeout*
622-
"timeout" ブロッキング時にリクエストを待つ時間 (例: ch_evalexpr()
629+
"timeout": time ブロッキング時にリクエストを待つ時間 (例: ch_evalexpr()
623630
を使用するとき。ミリ秒単位。デフォルトは 2000 (2 秒)
624631
です。
625632
*out_timeout* *err_timeout*
626-
"out_timeout" stdout のタイムアウト。パイプ使用時のみ。
627-
"err_timeout" stderr のタイムアウト。パイプ使用時のみ。
633+
"out_timeout": time stdout のタイムアウト。パイプ使用時のみ。
634+
"err_timeout": time stderr のタイムアウト。パイプ使用時のみ。
628635
Note: "timeout" を設定すると、パーツ固有のモードが上書
629636
きされます。したがって、最初に "timeout" を設定し、後
630637
でパーツ固有のモードを設定します。
@@ -636,8 +643,9 @@ job_setoptions(job, {options}) を使用して、ジョブの開始後にいく
636643
デフォルトは "term" です。
637644

638645
*job-term*
639-
"term":"open" ターミナルを起動し、ジョブ stdin/stdout/stderr を接続
640-
します。
646+
"term": "open" 新しいウィンドウでターミナルを起動し、ジョブ
647+
stdin/stdout/stderr を接続します。`:terminal` を使用す
648+
ることと同じです。
641649
NOTE: まだ実装されていません!
642650

643651
"channel": {channel} 新しいチャネルを作成する代わりに、既存のチャネルを使用
@@ -647,6 +655,11 @@ job_setoptions(job, {options}) を使用して、ジョブの開始後にいく
647655
性があります。
648656
既存のコールバックやその他の設定が残っています。
649657

658+
"pty": 1 可能であれば、パイプのかわりに pty (疑似 tty) を使いま
659+
す。これは端末ウィンドウとの組み合わせで最も便利です。
660+
|terminal| を参照。
661+
{Unix系システムのみ}
662+
650663
*job-in_io* *in_top* *in_bot* *in_name* *in_buf*
651664
"in_io": "null" stdin を切断する (/dev/null から読み込む)
652665
"in_io": "pipe" 標準入力がチャネルに接続されている (デフォルト)
@@ -687,6 +700,10 @@ job_setoptions(job, {options}) を使用して、ジョブの開始後にいく
687700
"block_write": number テストのためにのみ: stdin への他のすべての書き込みをブ
688701
ロックするふりをする
689702

703+
"env": dict 新しいプロセスのための環境変数
704+
"cwd": "/path/to/dir" 新しいプロセスのためのカレント作業ディレクトリ。ディレ
705+
クトリが存在しない場合は、エラーが発生します
706+
690707

691708
バッファへの書き込み ~
692709
*out_io-buffer*
@@ -722,10 +739,6 @@ out_io または err_io モードが "buffer" で、コールバックがある
722739
output..." に設定するかどうかを指定するために使用できます。デフォルトではメッ
723740
セージを追加します。"err_msg" はチャネルエラーでも同じです。
724741

725-
'modifiable' オプションをオフにしたり、'modifiable' オフなバッファを書き込んだ
726-
りすることができます。つまり、行がバッファに追加されますが、ユーザーはバッファ
727-
を簡単に変更できません。
728-
729742
既存のバッファに 'modifiable' が指定されておらず、"out_modifiable" または
730743
"err_modifiable" オプションがゼロでない場合、エラーが発生し、バッファに書き込
731744
まれません。
@@ -761,5 +774,49 @@ output..." に設定するかどうかを指定するために使用できます
761774
762775
他のオプションについては、|job_stop()| 参照。
763776

777+
==============================================================================
778+
12. プロンプトバッファを使う *prompt-buffer*
779+
780+
Vimのウィンドウでジョブのための入力をタイプしたい場合、いくつかのオプションが
781+
あります:
782+
- 通常のバッファを使用して、すべての起こりうるコマンドを自分で処理します。
783+
たくさんの起こりうるコマンドが存在するので、これは複雑になります。
784+
- 端末ウィンドウを使用します。入力した内容がジョブに直接送られ、ジョブの出力が
785+
ウィンドウに直接表示される場合は、これはうまく機能します。
786+
|terminal-window| 参照。
787+
- プロンプトウィンドウを使用します。これは、Vimでジョブからの出力 (フィルタリ
788+
ングされている可能性もある) を表示している間に、ジョブのための行を入力してい
789+
るときにうまく動作します。
790+
791+
プロンプトバッファは、'buftype' を "prompt" に設定することによって作成されま
792+
す。通常は、新規作成バッファでのみおこないます。
793+
794+
ユーザーは、バッファの最後の行に1行のテキストを編集して入力することができます。
795+
プロンプト行でEnterキーを押すと、|prompt_setcallback()| で設定されたコールバッ
796+
クが呼び出されます。通常は、その行をジョブに送信します。別のコールバックは、
797+
ジョブからの出力を受け取り、バッファ内のプロンプトの下 (次のプロンプトの上) に
798+
表示します。
799+
800+
プロンプトの後の最後の行のテキストのみが編集可能です。残りのバッファはノーマル
801+
モードのコマンドでは変更できません。|append()| などの関数を呼び出すことで変更
802+
できます。他のコマンドを使用すると、バッファを壊す可能性があります。
803+
804+
'buftype' を "prompt" に設定した後、Vimは自動的に挿入モードを開始しません。挿
805+
入モードに入るには `:startinsert` を使います。これにより、ユーザーは行の入力を
806+
開始できます。
807+
808+
プロンプトのテキストは、|prompt_setprompt()| 関数で設定できます。
809+
810+
ユーザーはノーマルモードに移行し、バッファ内を移動できます。これは、古い出力の
811+
参照やテキストのコピーに便利です。
812+
813+
CTRL-W キーを使用して次のウィンドウに切り替えるための CTRL-W w などのウィンド
814+
ウコマンドを開始できます。これは挿入モードでも機能します (単語を削除するには
815+
Shift-CTRL-W を使用します)。ウィンドウを離れるとき挿入モードは停止します。プロ
816+
ンプトウィンドウに戻ると、挿入モードが復元されます。
817+
818+
"a", "i", "A" や "I" などの挿入モードを開始するコマンドは、最終行にカーソルを
819+
移動します。"A" は行頭に移動し、"I" は行頭に移動します。
820+
764821

765-
vim:tw=78:ts=8:ft=help:norl:
822+
vim:tw=78:ts=8:noet:ft=help:norl:

en/channel.txt

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*channel.txt* For Vim version 8.0. Last change: 2016 Dec 02
1+
*channel.txt* For Vim version 8.1. Last change: 2018 Apr 18
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -22,6 +22,7 @@ The Netbeans interface also uses a channel. |netbeans|
2222
9. Starting a job without a channel |job-start-nochannel|
2323
10. Job options |job-options|
2424
11. Controlling a job |job-control|
25+
12. Using a prompt buffer |prompt-buffer|
2526

2627
{Vi does not have any of these features}
2728
{only when compiled with the |+channel| feature for channel stuff}
@@ -55,7 +56,7 @@ JS JavaScript style JSON-like encoding |js_encode()|
5556
Common combination are:
5657
- Using a job connected through pipes in NL mode. E.g., to run a style
5758
checker and receive errors and warnings.
58-
- Using a deamon, connecting over a socket in JSON mode. E.g. to lookup
59+
- Using a daemon, connecting over a socket in JSON mode. E.g. to lookup
5960
cross-references in a database.
6061

6162
==============================================================================
@@ -427,8 +428,8 @@ When no message was available then the result is v:none for a JSON or JS mode
427428
channels, an empty string for a RAW or NL channel. You can use |ch_canread()|
428429
to check if there is something to read.
429430

430-
Note that when there is no callback message are dropped. To avoid that add a
431-
close callback to the channel.
431+
Note that when there is no callback, messages are dropped. To avoid that add
432+
a close callback to the channel.
432433

433434
To read all output from a RAW channel that is available: >
434435
let output = ch_readraw(channel)
@@ -489,6 +490,11 @@ If you want to handle both stderr and stdout with one handler use the
489490
"callback" option: >
490491
let job = job_start(command, {"callback": "MyHandler"})
491492
493+
Depending on the system, starting a job can put Vim in the background, the
494+
started job gets the focus. To avoid that, use the `foreground()` function.
495+
This might not always work when called early, put in the callback handler or
496+
use a timer to call it after the job has started.
497+
492498
You can send a message to the command with ch_evalraw(). If the channel is in
493499
JSON or JS mode you can use ch_evalexpr().
494500

@@ -513,7 +519,7 @@ By default this reads the whole buffer. This can be changed with the "in_top"
513519
and "in_bot" options.
514520

515521
A special mode is when "in_top" is set to zero and "in_bot" is not set: Every
516-
time a line is added to the buffer, the last-but-one line will be send to the
522+
time a line is added to the buffer, the last-but-one line will be sent to the
517523
job stdin. This allows for editing the last line and sending it when pressing
518524
Enter.
519525
*channel-close-in*
@@ -606,7 +612,7 @@ See |job_setoptions()| and |ch_setoptions()|.
606612
"close_cb": handler Callback for when the channel is closed. Same as
607613
"close_cb" on |ch_open()|, see |close_cb|.
608614
*job-drop*
609-
"drop" Specifies when to drop messages. Same as "drop" on
615+
"drop": when Specifies when to drop messages. Same as "drop" on
610616
|ch_open()|, see |channel-drop|. For "auto" the
611617
exit_cb is not considered.
612618
*job-exit_cb*
@@ -619,12 +625,12 @@ See |job_setoptions()| and |ch_setoptions()|.
619625
Note that data can be buffered, callbacks may still be
620626
called after the process ends.
621627
*job-timeout*
622-
"timeout" The time to wait for a request when blocking, E.g.
628+
"timeout": time The time to wait for a request when blocking, E.g.
623629
when using ch_evalexpr(). In milliseconds. The
624630
default is 2000 (2 seconds).
625631
*out_timeout* *err_timeout*
626-
"out_timeout" Timeout for stdout. Only when using pipes.
627-
"err_timeout" Timeout for stderr. Only when using pipes.
632+
"out_timeout": time Timeout for stdout. Only when using pipes.
633+
"err_timeout": time Timeout for stderr. Only when using pipes.
628634
Note: when setting "timeout" the part specific mode is
629635
overwritten. Therefore set "timeout" first and the
630636
part specific mode later.
@@ -636,8 +642,9 @@ See |job_setoptions()| and |ch_setoptions()|.
636642
The default is "term".
637643

638644
*job-term*
639-
"term": "open" Start a terminal and connect the job
640-
stdin/stdout/stderr to it.
645+
"term": "open" Start a terminal in a new window and connect the job
646+
stdin/stdout/stderr to it. Similar to using
647+
`:terminal`.
641648
NOTE: Not implemented yet!
642649

643650
"channel": {channel} Use an existing channel instead of creating a new one.
@@ -647,6 +654,11 @@ See |job_setoptions()| and |ch_setoptions()|.
647654
cause I/O errors.
648655
Existing callbacks and other settings remain.
649656

657+
"pty": 1 Use a pty (pseudo-tty) instead of a pipe when
658+
possible. This is most useful in combination with a
659+
terminal window, see |terminal|.
660+
{only on Unix and Unix-like systems}
661+
650662
*job-in_io* *in_top* *in_bot* *in_name* *in_buf*
651663
"in_io": "null" disconnect stdin (read from /dev/null)
652664
"in_io": "pipe" stdin is connected to the channel (default)
@@ -685,6 +697,10 @@ See |job_setoptions()| and |ch_setoptions()|.
685697
"block_write": number only for testing: pretend every other write to stdin
686698
will block
687699

700+
"env": dict environment variables for the new process
701+
"cwd": "/path/to/dir" current working directory for the new process;
702+
if the directory does not exist an error is given
703+
688704

689705
Writing to a buffer ~
690706
*out_io-buffer*
@@ -720,10 +736,6 @@ The "out_msg" option can be used to specify whether a new buffer will have the
720736
first line set to "Reading from channel output...". The default is to add the
721737
message. "err_msg" does the same for channel error.
722738

723-
'modifiable' option off, or write to a buffer that has 'modifiable' off. That
724-
means that lines will be appended to the buffer, but the user can't easily
725-
change the buffer.
726-
727739
When an existing buffer is to be written where 'modifiable' is off and the
728740
"out_modifiable" or "err_modifiable" options is not zero, an error is given
729741
and the buffer will not be written to.
@@ -759,5 +771,49 @@ signals. E.g. to force a job to stop, "kill it": >
759771
760772
For more options see |job_stop()|.
761773

774+
==============================================================================
775+
12. Using a prompt buffer *prompt-buffer*
776+
777+
If you want to type input for the job in a Vim window you have a few options:
778+
- Use a normal buffer and handle all possible commands yourself.
779+
This will be complicated, since there are so many possible commands.
780+
- Use a terminal window. This works well if what you type goes directly to
781+
the job and the job output is directly displayed in the window.
782+
See |terminal-window|.
783+
- Use a prompt window. This works well when entering a line for the job in Vim
784+
while displaying (possibly filtered) output from the job.
785+
786+
A prompt buffer is created by setting 'buftype' to "prompt". You would
787+
normally only do that in a newly created buffer.
788+
789+
The user can edit and enter one line of text at the very last line of the
790+
buffer. When pressing Enter in the prompt line the callback set with
791+
|prompt_setcallback()| is invoked. It would normally send the line to a job.
792+
Another callback would receive the output from the job and display it in the
793+
buffer, below the prompt (and above the next prompt).
794+
795+
Only the text in the last line, after the prompt, is editable. The rest of the
796+
buffer is not modifiable with Normal mode commands. It can be modified by
797+
calling functions, such as |append()|. Using other commands may mess up the
798+
buffer.
799+
800+
After setting 'buftype' to "prompt" Vim does not automatically start Insert
801+
mode, use `:startinsert` if you want to enter Insert mode, so that the user
802+
can start typing a line.
803+
804+
The text of the prompt can be set with the |prompt_setprompt()| function.
805+
806+
The user can go to Normal mode and navigate through the buffer. This can be
807+
useful see older output or copy text.
808+
809+
The CTRL-W key can be used to start a window command, such as CTRL-W w to
810+
switch to the next window. This also works in Insert mode (use Shift-CTRL-W
811+
to delete a word). When leaving the window Insert mode will be stopped. When
812+
coming back to the prompt window Insert mode will be restored.
813+
814+
Any command that starts Insert mode, such as "a", "i", "A" and "I", will move
815+
the cursor to the last line. "A" will move to the end of the line, "I" to the
816+
start of the line.
817+
762818

763-
vim:tw=78:ts=8:ft=help:norl:
819+
vim:tw=78:ts=8:noet:ft=help:norl:

0 commit comments

Comments
 (0)