@@ -9662,7 +9662,26 @@ f_bufloaded(typval_T *argvars, typval_T *rettv)
96629662 rettv->vval.v_number = (buf != NULL && buf->b_ml.ml_mfp != NULL);
96639663}
96649664
9665- static buf_T *get_buf_tv(typval_T *tv, int curtab_only);
9665+ static buf_T *
9666+ buflist_find_by_name(char_u *name, int curtab_only)
9667+ {
9668+ int save_magic;
9669+ char_u *save_cpo;
9670+ buf_T *buf;
9671+
9672+ /* Ignore 'magic' and 'cpoptions' here to make scripts portable */
9673+ save_magic = p_magic;
9674+ p_magic = TRUE;
9675+ save_cpo = p_cpo;
9676+ p_cpo = (char_u *)"";
9677+
9678+ buf = buflist_findnr(buflist_findpat(name, name + STRLEN(name),
9679+ TRUE, FALSE, curtab_only));
9680+
9681+ p_magic = save_magic;
9682+ p_cpo = save_cpo;
9683+ return buf;
9684+ }
96669685
96679686/*
96689687 * Get buffer by number or pattern.
@@ -9671,8 +9690,6 @@ static buf_T *get_buf_tv(typval_T *tv, int curtab_only);
96719690get_buf_tv(typval_T *tv, int curtab_only)
96729691{
96739692 char_u *name = tv->vval.v_string;
9674- int save_magic;
9675- char_u *save_cpo;
96769693 buf_T *buf;
96779694
96789695 if (tv->v_type == VAR_NUMBER)
@@ -9684,17 +9701,7 @@ get_buf_tv(typval_T *tv, int curtab_only)
96849701 if (name[0] == '$' && name[1] == NUL)
96859702 return lastbuf;
96869703
9687- /* Ignore 'magic' and 'cpoptions' here to make scripts portable */
9688- save_magic = p_magic;
9689- p_magic = TRUE;
9690- save_cpo = p_cpo;
9691- p_cpo = (char_u *)"";
9692-
9693- buf = buflist_findnr(buflist_findpat(name, name + STRLEN(name),
9694- TRUE, FALSE, curtab_only));
9695-
9696- p_magic = save_magic;
9697- p_cpo = save_cpo;
9704+ buf = buflist_find_by_name(name, curtab_only);
96989705
96999706 /* If not found, try expanding the name, like done for bufexists(). */
97009707 if (buf == NULL)
@@ -10110,6 +10117,30 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported)
1011010117 opt->jo_io_name[part] =
1011110118 get_tv_string_buf_chk(item, opt->jo_io_name_buf[part]);
1011210119 }
10120+ else if (STRCMP(hi->hi_key, "in-top") == 0
10121+ || STRCMP(hi->hi_key, "in-bot") == 0)
10122+ {
10123+ linenr_T *lp;
10124+
10125+ if (!(supported & JO_OUT_IO))
10126+ break;
10127+ if (hi->hi_key[3] == 't')
10128+ {
10129+ lp = &opt->jo_in_top;
10130+ opt->jo_set |= JO_IN_TOP;
10131+ }
10132+ else
10133+ {
10134+ lp = &opt->jo_in_bot;
10135+ opt->jo_set |= JO_IN_BOT;
10136+ }
10137+ *lp = get_tv_number(item);
10138+ if (*lp < 0)
10139+ {
10140+ EMSG2(_(e_invarg2), get_tv_string(item));
10141+ return FAIL;
10142+ }
10143+ }
1011310144 else if (STRCMP(hi->hi_key, "callback") == 0)
1011410145 {
1011510146 if (!(supported & JO_CALLBACK))
@@ -15103,6 +15134,29 @@ f_job_start(typval_T *argvars UNUSED, typval_T *rettv)
1510315134 JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL
1510415135 + JO_STOPONEXIT + JO_EXIT_CB + JO_OUT_IO) == FAIL)
1510515136 return;
15137+
15138+ if ((opt.jo_set & JO_IN_IO) && opt.jo_io[PART_IN] == JIO_BUFFER)
15139+ {
15140+ buf_T *buf;
15141+
15142+ /* check that we can find the buffer before starting the job */
15143+ if (!(opt.jo_set & JO_IN_NAME))
15144+ {
15145+ EMSG(_("E915: in-io buffer requires in-name to be set"));
15146+ return;
15147+ }
15148+ buf = buflist_find_by_name(opt.jo_io_name[PART_IN], FALSE);
15149+ if (buf == NULL)
15150+ return;
15151+ if (buf->b_ml.ml_mfp == NULL)
15152+ {
15153+ EMSG2(_("E918: buffer must be loaded: %s"),
15154+ opt.jo_io_name[PART_IN]);
15155+ return;
15156+ }
15157+ job->jv_in_buf = buf;
15158+ }
15159+
1510615160 job_set_options(job, &opt);
1510715161
1510815162#ifndef USE_ARGV
@@ -15194,6 +15248,10 @@ f_job_start(typval_T *argvars UNUSED, typval_T *rettv)
1519415248 mch_start_job((char *)cmd, job, &opt);
1519515249#endif
1519615250
15251+ #ifdef FEAT_CHANNEL
15252+ channel_write_in(job->jv_channel);
15253+ #endif
15254+
1519715255theend:
1519815256#ifdef USE_ARGV
1519915257 vim_free(argv);
0 commit comments