@@ -9873,6 +9873,34 @@ get_callback(typval_T *arg)
98739873 return NULL;
98749874}
98759875
9876+ static int
9877+ handle_mode(typval_T *item, jobopt_T *opt, ch_mode_T *modep, int jo)
9878+ {
9879+ char_u *val = get_tv_string(item);
9880+
9881+ opt->jo_set |= jo;
9882+ if (STRCMP(val, "nl") == 0)
9883+ *modep = MODE_NL;
9884+ else if (STRCMP(val, "raw") == 0)
9885+ *modep = MODE_RAW;
9886+ else if (STRCMP(val, "js") == 0)
9887+ *modep = MODE_JS;
9888+ else if (STRCMP(val, "json") == 0)
9889+ *modep = MODE_JSON;
9890+ else
9891+ {
9892+ EMSG2(_(e_invarg2), val);
9893+ return FAIL;
9894+ }
9895+ return OK;
9896+ }
9897+
9898+ static void
9899+ clear_job_options(jobopt_T *opt)
9900+ {
9901+ vim_memset(opt, 0, sizeof(jobopt_T));
9902+ }
9903+
98769904/*
98779905 * Get the option entries from the dict in "tv", parse them and put the result
98789906 * in "opt".
@@ -9910,21 +9938,32 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported)
99109938 {
99119939 if (!(supported & JO_MODE))
99129940 break;
9913- opt->jo_set |= JO_MODE;
9914- val = get_tv_string(item);
9915- if (STRCMP(val, "nl") == 0)
9916- opt->jo_mode = MODE_NL;
9917- else if (STRCMP(val, "raw") == 0)
9918- opt->jo_mode = MODE_RAW;
9919- else if (STRCMP(val, "js") == 0)
9920- opt->jo_mode = MODE_JS;
9921- else if (STRCMP(val, "json") == 0)
9922- opt->jo_mode = MODE_JSON;
9923- else
9924- {
9925- EMSG2(_(e_invarg2), val);
9941+ if (handle_mode(item, opt, &opt->jo_mode, JO_MODE) == FAIL)
9942+ return FAIL;
9943+ }
9944+ else if (STRCMP(hi->hi_key, "in-mode") == 0)
9945+ {
9946+ if (!(supported & JO_IN_MODE))
9947+ break;
9948+ if (handle_mode(item, opt, &opt->jo_in_mode, JO_IN_MODE)
9949+ == FAIL)
9950+ return FAIL;
9951+ }
9952+ else if (STRCMP(hi->hi_key, "out-mode") == 0)
9953+ {
9954+ if (!(supported & JO_OUT_MODE))
9955+ break;
9956+ if (handle_mode(item, opt, &opt->jo_out_mode, JO_OUT_MODE)
9957+ == FAIL)
9958+ return FAIL;
9959+ }
9960+ else if (STRCMP(hi->hi_key, "err-mode") == 0)
9961+ {
9962+ if (!(supported & JO_ERR_MODE))
9963+ break;
9964+ if (handle_mode(item, opt, &opt->jo_err_mode, JO_ERR_MODE)
9965+ == FAIL)
99269966 return FAIL;
9927- }
99289967 }
99299968 else if (STRCMP(hi->hi_key, "callback") == 0)
99309969 {
@@ -9938,6 +9977,30 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported)
99389977 return FAIL;
99399978 }
99409979 }
9980+ else if (STRCMP(hi->hi_key, "out-cb") == 0)
9981+ {
9982+ if (!(supported & JO_OUT_CALLBACK))
9983+ break;
9984+ opt->jo_set |= JO_OUT_CALLBACK;
9985+ opt->jo_out_cb = get_callback(item);
9986+ if (opt->jo_out_cb == NULL)
9987+ {
9988+ EMSG2(_(e_invarg2), "out-db");
9989+ return FAIL;
9990+ }
9991+ }
9992+ else if (STRCMP(hi->hi_key, "err-cb") == 0)
9993+ {
9994+ if (!(supported & JO_ERR_CALLBACK))
9995+ break;
9996+ opt->jo_set |= JO_ERR_CALLBACK;
9997+ opt->jo_err_cb = get_callback(item);
9998+ if (opt->jo_err_cb == NULL)
9999+ {
10000+ EMSG2(_(e_invarg2), "err-cb");
10001+ return FAIL;
10002+ }
10003+ }
994110004 else if (STRCMP(hi->hi_key, "waittime") == 0)
994210005 {
994310006 if (!(supported & JO_WAITTIME))
@@ -9952,6 +10015,20 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported)
995210015 opt->jo_set |= JO_TIMEOUT;
995310016 opt->jo_timeout = get_tv_number(item);
995410017 }
10018+ else if (STRCMP(hi->hi_key, "out-timeout") == 0)
10019+ {
10020+ if (!(supported & JO_OUT_TIMEOUT))
10021+ break;
10022+ opt->jo_set |= JO_OUT_TIMEOUT;
10023+ opt->jo_out_timeout = get_tv_number(item);
10024+ }
10025+ else if (STRCMP(hi->hi_key, "err-timeout") == 0)
10026+ {
10027+ if (!(supported & JO_ERR_TIMEOUT))
10028+ break;
10029+ opt->jo_set |= JO_ERR_TIMEOUT;
10030+ opt->jo_err_timeout = get_tv_number(item);
10031+ }
995510032 else if (STRCMP(hi->hi_key, "part") == 0)
995610033 {
995710034 if (!(supported & JO_PART))
@@ -10107,12 +10184,11 @@ f_ch_open(typval_T *argvars, typval_T *rettv)
1010710184 }
1010810185
1010910186 /* parse options */
10187+ clear_job_options(&opt);
1011010188 opt.jo_mode = MODE_JSON;
10111- opt.jo_callback = NULL;
10112- opt.jo_waittime = 0;
1011310189 opt.jo_timeout = 2000;
1011410190 if (get_job_options(&argvars[1], &opt,
10115- JO_MODE + JO_CALLBACK + JO_WAITTIME + JO_TIMEOUT ) == FAIL)
10191+ JO_MODE_ALL + JO_CB_ALL + JO_WAITTIME + JO_TIMEOUT_ALL ) == FAIL)
1011610192 return;
1011710193 if (opt.jo_timeout < 0)
1011810194 {
@@ -10147,7 +10223,7 @@ common_channel_read(typval_T *argvars, typval_T *rettv, int raw)
1014710223 rettv->v_type = VAR_STRING;
1014810224 rettv->vval.v_string = NULL;
1014910225
10150- opt.jo_set = 0 ;
10226+ clear_job_options(& opt) ;
1015110227 if (get_job_options(&argvars[1], &opt, JO_TIMEOUT + JO_PART + JO_ID)
1015210228 == FAIL)
1015310229 return;
@@ -10219,7 +10295,7 @@ send_common(typval_T *argvars, char_u *text, int id, char *fun, int *part_read)
1021910295 part_send = channel_part_send(channel);
1022010296 *part_read = channel_part_read(channel);
1022110297
10222- opt.jo_callback = NULL ;
10298+ clear_job_options(& opt) ;
1022310299 if (get_job_options(&argvars[2], &opt, JO_CALLBACK) == FAIL)
1022410300 return NULL;
1022510301
@@ -10329,7 +10405,9 @@ f_ch_setoptions(typval_T *argvars, typval_T *rettv UNUSED)
1032910405 channel = get_channel_arg(&argvars[0]);
1033010406 if (channel == NULL)
1033110407 return;
10332- if (get_job_options(&argvars[1], &opt, JO_CALLBACK + JO_TIMEOUT) == FAIL)
10408+ clear_job_options(&opt);
10409+ if (get_job_options(&argvars[1], &opt,
10410+ JO_CB_ALL + JO_TIMEOUT_ALL + JO_MODE_ALL) == FAIL)
1033310411 return;
1033410412 channel_set_options(channel, &opt);
1033510413}
@@ -14684,9 +14762,10 @@ f_job_start(typval_T *argvars UNUSED, typval_T *rettv)
1468414762 rettv->vval.v_job->jv_status = JOB_FAILED;
1468514763
1468614764 /* Default mode is NL. */
14765+ clear_job_options(&opt);
1468714766 opt.jo_mode = MODE_NL;
14688- opt.jo_callback = NULL;
14689- if (get_job_options(&argvars[1], &opt, JO_MODE + JO_CALLBACK ) == FAIL)
14767+ if (get_job_options(&argvars[1], &opt,
14768+ JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL ) == FAIL)
1469014769 return;
1469114770
1469214771#ifndef USE_ARGV
0 commit comments