Mercurial > vim
diff src/eval.c @ 8386:3b9a306724ec v7.4.1485
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 3 22:51:40 2016 +0100
patch 7.4.1485
Problem: Job input from buffer is not implemented.
Solution: Implement it. Add "in-top" and "in-bot" options.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 03 Mar 2016 23:00:05 +0100 |
parents | 892d7dcf17ec |
children | be45d4921f1f |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -9662,28 +9662,13 @@ f_bufloaded(typval_T *argvars, typval_T rettv->vval.v_number = (buf != NULL && buf->b_ml.ml_mfp != NULL); } -static buf_T *get_buf_tv(typval_T *tv, int curtab_only); - -/* - * Get buffer by number or pattern. - */ static buf_T * -get_buf_tv(typval_T *tv, int curtab_only) -{ - char_u *name = tv->vval.v_string; +buflist_find_by_name(char_u *name, int curtab_only) +{ int save_magic; char_u *save_cpo; buf_T *buf; - if (tv->v_type == VAR_NUMBER) - return buflist_findnr((int)tv->vval.v_number); - if (tv->v_type != VAR_STRING) - return NULL; - if (name == NULL || *name == NUL) - return curbuf; - if (name[0] == '$' && name[1] == NUL) - return lastbuf; - /* Ignore 'magic' and 'cpoptions' here to make scripts portable */ save_magic = p_magic; p_magic = TRUE; @@ -9695,6 +9680,28 @@ get_buf_tv(typval_T *tv, int curtab_only p_magic = save_magic; p_cpo = save_cpo; + return buf; +} + +/* + * Get buffer by number or pattern. + */ + static buf_T * +get_buf_tv(typval_T *tv, int curtab_only) +{ + char_u *name = tv->vval.v_string; + buf_T *buf; + + if (tv->v_type == VAR_NUMBER) + return buflist_findnr((int)tv->vval.v_number); + if (tv->v_type != VAR_STRING) + return NULL; + if (name == NULL || *name == NUL) + return curbuf; + if (name[0] == '$' && name[1] == NUL) + return lastbuf; + + buf = buflist_find_by_name(name, curtab_only); /* If not found, try expanding the name, like done for bufexists(). */ if (buf == NULL) @@ -10110,6 +10117,30 @@ get_job_options(typval_T *tv, jobopt_T * opt->jo_io_name[part] = get_tv_string_buf_chk(item, opt->jo_io_name_buf[part]); } + else if (STRCMP(hi->hi_key, "in-top") == 0 + || STRCMP(hi->hi_key, "in-bot") == 0) + { + linenr_T *lp; + + if (!(supported & JO_OUT_IO)) + break; + if (hi->hi_key[3] == 't') + { + lp = &opt->jo_in_top; + opt->jo_set |= JO_IN_TOP; + } + else + { + lp = &opt->jo_in_bot; + opt->jo_set |= JO_IN_BOT; + } + *lp = get_tv_number(item); + if (*lp < 0) + { + EMSG2(_(e_invarg2), get_tv_string(item)); + return FAIL; + } + } else if (STRCMP(hi->hi_key, "callback") == 0) { if (!(supported & JO_CALLBACK)) @@ -15103,6 +15134,29 @@ f_job_start(typval_T *argvars UNUSED, ty JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL + JO_STOPONEXIT + JO_EXIT_CB + JO_OUT_IO) == FAIL) return; + + if ((opt.jo_set & JO_IN_IO) && opt.jo_io[PART_IN] == JIO_BUFFER) + { + buf_T *buf; + + /* check that we can find the buffer before starting the job */ + if (!(opt.jo_set & JO_IN_NAME)) + { + EMSG(_("E915: in-io buffer requires in-name to be set")); + return; + } + buf = buflist_find_by_name(opt.jo_io_name[PART_IN], FALSE); + if (buf == NULL) + return; + if (buf->b_ml.ml_mfp == NULL) + { + EMSG2(_("E918: buffer must be loaded: %s"), + opt.jo_io_name[PART_IN]); + return; + } + job->jv_in_buf = buf; + } + job_set_options(job, &opt); #ifndef USE_ARGV @@ -15194,6 +15248,10 @@ f_job_start(typval_T *argvars UNUSED, ty mch_start_job((char *)cmd, job, &opt); #endif +#ifdef FEAT_CHANNEL + channel_write_in(job->jv_channel); +#endif + theend: #ifdef USE_ARGV vim_free(argv);