0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 7.4.1485

Problem:    Job input from buffer is not implemented.
Solution:   Implement it.  Add "in-top" and "in-bot" options.
This commit is contained in:
Bram Moolenaar
2016-03-03 22:51:40 +01:00
parent c25558bff4
commit 014069a7ac
8 changed files with 177 additions and 24 deletions

View File

@@ -9662,28 +9662,13 @@ 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);
/*
* 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 @@ 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, 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);