@@ -507,6 +507,8 @@ static void f_ceil(typval_T *argvars, typval_T *rettv);
507507#endif
508508#ifdef FEAT_CHANNEL
509509static void f_ch_close(typval_T *argvars, typval_T *rettv);
510+ static void f_ch_evalexpr(typval_T *argvars, typval_T *rettv);
511+ static void f_ch_evalraw(typval_T *argvars, typval_T *rettv);
510512# ifdef FEAT_JOB
511513static void f_ch_getjob(typval_T *argvars, typval_T *rettv);
512514# endif
@@ -8201,6 +8203,8 @@ static struct fst
82018203#endif
82028204#ifdef FEAT_CHANNEL
82038205 {"ch_close", 1, 1, f_ch_close},
8206+ {"ch_evalexpr", 2, 3, f_ch_evalexpr},
8207+ {"ch_evalraw", 2, 3, f_ch_evalraw},
82048208# ifdef FEAT_JOB
82058209 {"ch_getjob", 1, 1, f_ch_getjob},
82068210# endif
@@ -10485,7 +10489,13 @@ f_ch_readraw(typval_T *argvars, typval_T *rettv)
1048510489 * Otherwise returns NULL.
1048610490 */
1048710491 static channel_T *
10488- send_common(typval_T *argvars, char_u *text, int id, char *fun, int *part_read)
10492+ send_common(
10493+ typval_T *argvars,
10494+ char_u *text,
10495+ int id,
10496+ int eval,
10497+ char *fun,
10498+ int *part_read)
1048910499{
1049010500 channel_T *channel;
1049110501 jobopt_T opt;
@@ -10502,9 +10512,17 @@ send_common(typval_T *argvars, char_u *text, int id, char *fun, int *part_read)
1050210512 return NULL;
1050310513
1050410514 /* Set the callback. An empty callback means no callback and not reading
10505- * the response. */
10515+ * the response. With "ch_evalexpr()" and "ch_evalraw()" a callback is not
10516+ * allowed. */
1050610517 if (opt.jo_callback != NULL && *opt.jo_callback != NUL)
10518+ {
10519+ if (eval)
10520+ {
10521+ EMSG2(_("E917: Cannot use a callback with %s()"), fun);
10522+ return NULL;
10523+ }
1050710524 channel_set_req_callback(channel, part_send, opt.jo_callback, id);
10525+ }
1050810526
1050910527 if (channel_send(channel, part_send, text, fun) == OK
1051010528 && opt.jo_callback == NULL)
@@ -10513,10 +10531,10 @@ send_common(typval_T *argvars, char_u *text, int id, char *fun, int *part_read)
1051310531}
1051410532
1051510533/*
10516- * "ch_sendexpr ()" function
10534+ * common for "ch_evalexpr ()" and "ch_sendexpr()"
1051710535 */
1051810536 static void
10519- f_ch_sendexpr (typval_T *argvars, typval_T *rettv)
10537+ ch_expr_common (typval_T *argvars, typval_T *rettv, int eval )
1052010538{
1052110539 char_u *text;
1052210540 typval_T *listtv;
@@ -10539,7 +10557,7 @@ f_ch_sendexpr(typval_T *argvars, typval_T *rettv)
1053910557 ch_mode = channel_get_mode(channel, part_send);
1054010558 if (ch_mode == MODE_RAW || ch_mode == MODE_NL)
1054110559 {
10542- EMSG(_("E912: cannot use ch_sendexpr() with a raw or nl channel"));
10560+ EMSG(_("E912: cannot use ch_evalexpr()/ ch_sendexpr() with a raw or nl channel"));
1054310561 return;
1054410562 }
1054510563
@@ -10549,9 +10567,10 @@ f_ch_sendexpr(typval_T *argvars, typval_T *rettv)
1054910567 if (text == NULL)
1055010568 return;
1055110569
10552- channel = send_common(argvars, text, id, "sendexpr", &part_read);
10570+ channel = send_common(argvars, text, id, eval,
10571+ eval ? "ch_evalexpr" : "ch_sendexpr", &part_read);
1055310572 vim_free(text);
10554- if (channel != NULL)
10573+ if (channel != NULL && eval )
1055510574 {
1055610575 /* TODO: timeout from options */
1055710576 timeout = channel_get_timeout(channel, part_read);
@@ -10570,10 +10589,28 @@ f_ch_sendexpr(typval_T *argvars, typval_T *rettv)
1057010589}
1057110590
1057210591/*
10573- * "ch_sendraw ()" function
10592+ * "ch_evalexpr ()" function
1057410593 */
1057510594 static void
10576- f_ch_sendraw(typval_T *argvars, typval_T *rettv)
10595+ f_ch_evalexpr(typval_T *argvars, typval_T *rettv)
10596+ {
10597+ ch_expr_common(argvars, rettv, TRUE);
10598+ }
10599+
10600+ /*
10601+ * "ch_sendexpr()" function
10602+ */
10603+ static void
10604+ f_ch_sendexpr(typval_T *argvars, typval_T *rettv)
10605+ {
10606+ ch_expr_common(argvars, rettv, FALSE);
10607+ }
10608+
10609+ /*
10610+ * common for "ch_evalraw()" and "ch_sendraw()"
10611+ */
10612+ static void
10613+ ch_raw_common(typval_T *argvars, typval_T *rettv, int eval)
1057710614{
1057810615 char_u buf[NUMBUFLEN];
1057910616 char_u *text;
@@ -10586,15 +10623,34 @@ f_ch_sendraw(typval_T *argvars, typval_T *rettv)
1058610623 rettv->vval.v_string = NULL;
1058710624
1058810625 text = get_tv_string_buf(&argvars[1], buf);
10589- channel = send_common(argvars, text, 0, "sendraw", &part_read);
10590- if (channel != NULL)
10626+ channel = send_common(argvars, text, 0, eval,
10627+ eval ? "ch_evalraw" : "ch_sendraw", &part_read);
10628+ if (channel != NULL && eval)
1059110629 {
1059210630 /* TODO: timeout from options */
1059310631 timeout = channel_get_timeout(channel, part_read);
1059410632 rettv->vval.v_string = channel_read_block(channel, part_read, timeout);
1059510633 }
1059610634}
1059710635
10636+ /*
10637+ * "ch_evalraw()" function
10638+ */
10639+ static void
10640+ f_ch_evalraw(typval_T *argvars, typval_T *rettv)
10641+ {
10642+ ch_raw_common(argvars, rettv, TRUE);
10643+ }
10644+
10645+ /*
10646+ * "ch_sendraw()" function
10647+ */
10648+ static void
10649+ f_ch_sendraw(typval_T *argvars, typval_T *rettv)
10650+ {
10651+ ch_raw_common(argvars, rettv, FALSE);
10652+ }
10653+
1059810654/*
1059910655 * "ch_setoptions()" function
1060010656 */
0 commit comments