summaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-03-03 22:51:40 +0100
committerBram Moolenaar <Bram@vim.org>2016-03-03 22:51:40 +0100
commit014069a7ac51557e531eb3c8b94e36f2193f6c21 (patch)
tree82f6fa36a91227356a4e120f6f6c24101369abc5 /src/eval.c
parentc25558bff4ed10d2642e6f5c016701641c494916 (diff)
patch 7.4.1485v7.4.1485
Problem: Job input from buffer is not implemented. Solution: Implement it. Add "in-top" and "in-bot" options.
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c86
1 files changed, 72 insertions, 14 deletions
diff --git a/src/eval.c b/src/eval.c
index 716706855c..23154061c4 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -9662,7 +9662,26 @@ f_bufloaded(typval_T *argvars, typval_T *rettv)
rettv->vval.v_number = (buf != NULL && buf->b_ml.ml_mfp != NULL);
}
-static buf_T *get_buf_tv(typval_T *tv, int curtab_only);
+ static buf_T *
+buflist_find_by_name(char_u *name, int curtab_only)
+{
+ int save_magic;
+ char_u *save_cpo;
+ buf_T *buf;
+
+ /* Ignore 'magic' and 'cpoptions' here to make scripts portable */
+ save_magic = p_magic;
+ p_magic = TRUE;
+ save_cpo = p_cpo;
+ p_cpo = (char_u *)"";
+
+ buf = buflist_findnr(buflist_findpat(name, name + STRLEN(name),
+ TRUE, FALSE, curtab_only));
+
+ p_magic = save_magic;
+ p_cpo = save_cpo;
+ return buf;
+}
/*
* Get buffer by number or pattern.
@@ -9671,8 +9690,6 @@ static buf_T *get_buf_tv(typval_T *tv, int curtab_only);
get_buf_tv(typval_T *tv, int curtab_only)
{
char_u *name = tv->vval.v_string;
- int save_magic;
- char_u *save_cpo;
buf_T *buf;
if (tv->v_type == VAR_NUMBER)
@@ -9684,17 +9701,7 @@ get_buf_tv(typval_T *tv, int curtab_only)
if (name[0] == '$' && name[1] == NUL)
return lastbuf;
- /* Ignore 'magic' and 'cpoptions' here to make scripts portable */
- save_magic = p_magic;
- p_magic = TRUE;
- save_cpo = p_cpo;
- p_cpo = (char_u *)"";
-
- buf = buflist_findnr(buflist_findpat(name, name + STRLEN(name),
- TRUE, FALSE, curtab_only));
-
- p_magic = save_magic;
- p_cpo = save_cpo;
+ 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, int supported)
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, typval_T *rettv)
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, typval_T *rettv)
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);