diff options
-rw-r--r-- | src/channel.c | 13 | ||||
-rw-r--r-- | src/eval.c | 21 | ||||
-rw-r--r-- | src/proto/channel.pro | 1 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 36 insertions, 1 deletions
diff --git a/src/channel.c b/src/channel.c index 8e36808a4b..fef6de504a 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1514,4 +1514,17 @@ set_ref_in_channel(int copyID) } return abort; } + +/* + * Return the mode of channel "idx". + * If "idx" is invalid returns MODE_JSON. + */ + ch_mode_T +channel_get_mode(int idx) +{ + if (idx < 0 || idx >= channel_count) + return MODE_JSON; + return channels[idx].ch_mode; +} + #endif /* FEAT_CHANNEL */ diff --git a/src/eval.c b/src/eval.c index 787f0f0343..e3edff6df7 100644 --- a/src/eval.c +++ b/src/eval.c @@ -9924,7 +9924,10 @@ send_common(typval_T *argvars, char_u *text, int id, char *fun) ch_idx = get_channel_arg(&argvars[0]); if (ch_idx < 0) + { + EMSG(_(e_invarg)); return -1; + } if (argvars[2].v_type != VAR_UNKNOWN) { @@ -9952,13 +9955,29 @@ f_ch_sendexpr(typval_T *argvars, typval_T *rettv) typval_T *listtv; int ch_idx; int id; + ch_mode_T ch_mode; /* return an empty string by default */ rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; + ch_idx = get_channel_arg(&argvars[0]); + if (ch_idx < 0) + { + EMSG(_(e_invarg)); + return; + } + + ch_mode = channel_get_mode(ch_idx); + if (ch_mode == MODE_RAW) + { + EMSG(_("E912: cannot use ch_sendexpr() with a raw channel")); + return; + } + id = channel_get_id(); - text = json_encode_nr_expr(id, &argvars[1], 0); + text = json_encode_nr_expr(id, &argvars[1], + ch_mode == MODE_JS ? JSON_JS : 0); if (text == NULL) return; diff --git a/src/proto/channel.pro b/src/proto/channel.pro index 693d2c223d..4de1720139 100644 --- a/src/proto/channel.pro +++ b/src/proto/channel.pro @@ -24,4 +24,5 @@ int channel_select_setup(int maxfd_in, void *rfds_in); int channel_select_check(int ret_in, void *rfds_in); int channel_parse_messages(void); int set_ref_in_channel(int copyID); +ch_mode_T channel_get_mode(int idx); /* vim: set ft=c : */ diff --git a/src/version.c b/src/version.c index a857cf1fc6..220b2c5cbf 100644 --- a/src/version.c +++ b/src/version.c @@ -748,6 +748,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1288, +/**/ 1287, /**/ 1286, |