patch 7.4.1485
Problem: Job input from buffer is not implemented.
Solution: Implement it. Add "in-top" and "in-bot" options.
diff --git a/src/eval.c b/src/eval.c
index 7167068..2315406 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -9662,28 +9662,13 @@
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)
+buflist_find_by_name(char_u *name, 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)
- 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 @@
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 @@
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 @@
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 @@
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);