From 151f656e171f6ffbb0cbeb343cbcf2ffac0c36b0 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Mon, 7 Mar 2016 21:19:38 +0100 Subject: [PATCH] patch 7.4.1509 Problem: Keeping both a variable for a job and the channel it refers to is a hassle. Solution: Allow passing the job where a channel is expected. (Damien) --- src/eval.c | 16 ++++++++++++---- src/testdir/test_channel.vim | 12 ++++++------ src/version.c | 2 ++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/eval.c b/src/eval.c index f65c9a0b1..70a1daa44 100644 --- a/src/eval.c +++ b/src/eval.c @@ -10285,14 +10285,22 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported) static channel_T * get_channel_arg(typval_T *tv) { - channel_T *channel; + channel_T *channel = NULL; - if (tv->v_type != VAR_CHANNEL) + if (tv->v_type == VAR_JOB) + { + if (tv->vval.v_job != NULL) + channel = tv->vval.v_job->jv_channel; + } + else if (tv->v_type == VAR_CHANNEL) + { + channel = tv->vval.v_channel; + } + else { EMSG2(_(e_invarg2), get_tv_string(tv)); return NULL; } - channel = tv->vval.v_channel; if (channel == NULL || !channel_is_open(channel)) { @@ -15106,7 +15114,7 @@ f_job_setoptions(typval_T *argvars, typval_T *rettv UNUSED) * "job_start()" function */ static void -f_job_start(typval_T *argvars UNUSED, typval_T *rettv) +f_job_start(typval_T *argvars, typval_T *rettv) { job_T *job; char_u *cmd = NULL; diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim index 299bb2ba7..5a315679c 100644 --- a/src/testdir/test_channel.vim +++ b/src/testdir/test_channel.vim @@ -463,16 +463,16 @@ func Test_raw_pipe() let job = job_start(s:python . " test_channel_pipe.py", {'mode': 'raw'}) call assert_equal("run", job_status(job)) try - let handle = job_getchannel(job) - call ch_sendraw(handle, "echo something\n") - let msg = ch_readraw(handle) + " For a change use the job where a channel is expected. + call ch_sendraw(job, "echo something\n") + let msg = ch_readraw(job) call assert_equal("something\n", substitute(msg, "\r", "", 'g')) - call ch_sendraw(handle, "double this\n") - let msg = ch_readraw(handle) + call ch_sendraw(job, "double this\n") + let msg = ch_readraw(job) call assert_equal("this\nAND this\n", substitute(msg, "\r", "", 'g')) - let reply = ch_evalraw(handle, "quit\n", {'timeout': 100}) + let reply = ch_evalraw(job, "quit\n", {'timeout': 100}) call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g')) finally call job_stop(job) diff --git a/src/version.c b/src/version.c index c4012e265..417a0e374 100644 --- a/src/version.c +++ b/src/version.c @@ -743,6 +743,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1509, /**/ 1508, /**/ -- 2.50.1