mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.0.0916: cannot specify properties of window for terminal open
Problem: Cannot specify properties of window for when opening a window for a finished terminal job. Solution: Add "term_opencmd".
This commit is contained in:
@@ -8085,6 +8085,12 @@ term_start({cmd}, {options}) *term_start()*
|
|||||||
"open": open window if needed
|
"open": open window if needed
|
||||||
Note that "open" can be interruptive.
|
Note that "open" can be interruptive.
|
||||||
See |term++close| and |term++open|.
|
See |term++close| and |term++open|.
|
||||||
|
"term_opencmd" command to use for opening the window when
|
||||||
|
"open" is used for "term_finish"; must
|
||||||
|
have "%d" where the buffer number goes,
|
||||||
|
e.g. "10split|buffer %d"; when not
|
||||||
|
specified "botright sbuf %d" is used
|
||||||
|
|
||||||
{only available when compiled with the |+terminal| feature}
|
{only available when compiled with the |+terminal| feature}
|
||||||
|
|
||||||
term_wait({buf} [, {time}]) *term_wait()*
|
term_wait({buf} [, {time}]) *term_wait()*
|
||||||
|
@@ -4434,6 +4434,28 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2)
|
|||||||
opt->jo_set2 |= JO2_TERM_FINISH;
|
opt->jo_set2 |= JO2_TERM_FINISH;
|
||||||
opt->jo_term_finish = *val;
|
opt->jo_term_finish = *val;
|
||||||
}
|
}
|
||||||
|
else if (STRCMP(hi->hi_key, "term_opencmd") == 0)
|
||||||
|
{
|
||||||
|
char_u *p;
|
||||||
|
|
||||||
|
if (!(supported2 & JO2_TERM_OPENCMD))
|
||||||
|
break;
|
||||||
|
opt->jo_set2 |= JO2_TERM_OPENCMD;
|
||||||
|
p = opt->jo_term_opencmd = get_tv_string_chk(item);
|
||||||
|
if (p != NULL)
|
||||||
|
{
|
||||||
|
/* Must have %d and no other %. */
|
||||||
|
p = vim_strchr(p, '%');
|
||||||
|
if (p != NULL && (p[1] != 'd'
|
||||||
|
|| vim_strchr(p + 2, '%') != NULL))
|
||||||
|
p = NULL;
|
||||||
|
}
|
||||||
|
if (p == NULL)
|
||||||
|
{
|
||||||
|
EMSG2(_(e_invarg2), "term_opencmd");
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (STRCMP(hi->hi_key, "term_rows") == 0)
|
else if (STRCMP(hi->hi_key, "term_rows") == 0)
|
||||||
{
|
{
|
||||||
if (!(supported2 & JO2_TERM_ROWS))
|
if (!(supported2 & JO2_TERM_ROWS))
|
||||||
|
@@ -1693,7 +1693,8 @@ struct channel_S {
|
|||||||
#define JO2_VERTICAL 0x0100 /* "vertical" */
|
#define JO2_VERTICAL 0x0100 /* "vertical" */
|
||||||
#define JO2_CURWIN 0x0200 /* "curwin" */
|
#define JO2_CURWIN 0x0200 /* "curwin" */
|
||||||
#define JO2_HIDDEN 0x0400 /* "hidden" */
|
#define JO2_HIDDEN 0x0400 /* "hidden" */
|
||||||
#define JO2_ALL 0x07FF
|
#define JO2_TERM_OPENCMD 0x0800 /* "term_opencmd" */
|
||||||
|
#define JO2_ALL 0x0FFF
|
||||||
|
|
||||||
#define JO_MODE_ALL (JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE)
|
#define JO_MODE_ALL (JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE)
|
||||||
#define JO_CB_ALL \
|
#define JO_CB_ALL \
|
||||||
@@ -1757,6 +1758,7 @@ typedef struct
|
|||||||
int jo_curwin;
|
int jo_curwin;
|
||||||
int jo_hidden;
|
int jo_hidden;
|
||||||
char_u *jo_term_name;
|
char_u *jo_term_name;
|
||||||
|
char_u *jo_term_opencmd;
|
||||||
int jo_term_finish;
|
int jo_term_finish;
|
||||||
#endif
|
#endif
|
||||||
} jobopt_T;
|
} jobopt_T;
|
||||||
|
@@ -36,8 +36,6 @@
|
|||||||
* that buffer, attributes come from the scrollback buffer tl_scrollback.
|
* that buffer, attributes come from the scrollback buffer tl_scrollback.
|
||||||
*
|
*
|
||||||
* TODO:
|
* TODO:
|
||||||
* - When using term_finish "open" have a way to specify how the window is to
|
|
||||||
* be opened. E.g. term_opencmd "10split buffer %d".
|
|
||||||
* - support different cursor shapes, colors and attributes
|
* - support different cursor shapes, colors and attributes
|
||||||
* - make term_getcursor() return type (none/block/bar/underline) and
|
* - make term_getcursor() return type (none/block/bar/underline) and
|
||||||
* attributes (color, blink, etc.)
|
* attributes (color, blink, etc.)
|
||||||
@@ -119,6 +117,7 @@ struct terminal_S {
|
|||||||
int tl_normal_mode; /* TRUE: Terminal-Normal mode */
|
int tl_normal_mode; /* TRUE: Terminal-Normal mode */
|
||||||
int tl_channel_closed;
|
int tl_channel_closed;
|
||||||
int tl_finish; /* 'c' for ++close, 'o' for ++open */
|
int tl_finish; /* 'c' for ++close, 'o' for ++open */
|
||||||
|
char_u *tl_opencmd;
|
||||||
|
|
||||||
#ifdef WIN3264
|
#ifdef WIN3264
|
||||||
void *tl_winpty_config;
|
void *tl_winpty_config;
|
||||||
@@ -365,6 +364,9 @@ term_start(char_u *cmd, jobopt_T *opt, int forceit)
|
|||||||
}
|
}
|
||||||
curbuf->b_fname = curbuf->b_ffname;
|
curbuf->b_fname = curbuf->b_ffname;
|
||||||
|
|
||||||
|
if (opt->jo_term_opencmd != NULL)
|
||||||
|
term->tl_opencmd = vim_strsave(opt->jo_term_opencmd);
|
||||||
|
|
||||||
set_string_option_direct((char_u *)"buftype", -1,
|
set_string_option_direct((char_u *)"buftype", -1,
|
||||||
(char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
|
(char_u *)"terminal", OPT_FREE|OPT_LOCAL, 0);
|
||||||
|
|
||||||
@@ -514,6 +516,7 @@ free_terminal(buf_T *buf)
|
|||||||
term_free_vterm(term);
|
term_free_vterm(term);
|
||||||
vim_free(term->tl_title);
|
vim_free(term->tl_title);
|
||||||
vim_free(term->tl_status_text);
|
vim_free(term->tl_status_text);
|
||||||
|
vim_free(term->tl_opencmd);
|
||||||
vim_free(term);
|
vim_free(term);
|
||||||
buf->b_term = NULL;
|
buf->b_term = NULL;
|
||||||
}
|
}
|
||||||
@@ -1539,7 +1542,9 @@ term_channel_closed(channel_T *ch)
|
|||||||
|
|
||||||
/* TODO: use term_opencmd */
|
/* TODO: use term_opencmd */
|
||||||
ch_log(NULL, "terminal job finished, opening window");
|
ch_log(NULL, "terminal job finished, opening window");
|
||||||
vim_snprintf(buf, sizeof(buf), "botright sbuf %d", fnum);
|
vim_snprintf(buf, sizeof(buf),
|
||||||
|
term->tl_opencmd == NULL
|
||||||
|
? "botright sbuf %d" : term->tl_opencmd, fnum);
|
||||||
do_cmdline_cmd((char_u *)buf);
|
do_cmdline_cmd((char_u *)buf);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -2434,7 +2439,7 @@ f_term_start(typval_T *argvars, typval_T *rettv)
|
|||||||
&& get_job_options(&argvars[1], &opt,
|
&& get_job_options(&argvars[1], &opt,
|
||||||
JO_TIMEOUT_ALL + JO_STOPONEXIT
|
JO_TIMEOUT_ALL + JO_STOPONEXIT
|
||||||
+ JO_EXIT_CB + JO_CLOSE_CALLBACK,
|
+ JO_EXIT_CB + JO_CLOSE_CALLBACK,
|
||||||
JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN
|
JO2_TERM_NAME + JO2_TERM_FINISH + JO2_HIDDEN + JO2_TERM_OPENCMD
|
||||||
+ JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN
|
+ JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN
|
||||||
+ JO2_CWD + JO2_ENV) == FAIL)
|
+ JO2_CWD + JO2_ENV) == FAIL)
|
||||||
return;
|
return;
|
||||||
|
@@ -320,7 +320,7 @@ func Test_terminal_curwin()
|
|||||||
|
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_finish_close()
|
func Test_finish_open_close()
|
||||||
call assert_equal(1, winnr('$'))
|
call assert_equal(1, winnr('$'))
|
||||||
|
|
||||||
if s:python != ''
|
if s:python != ''
|
||||||
@@ -371,6 +371,19 @@ func Test_finish_close()
|
|||||||
call WaitFor("winnr('$') == 2", waittime)
|
call WaitFor("winnr('$') == 2", waittime)
|
||||||
call assert_equal(2, winnr('$'))
|
call assert_equal(2, winnr('$'))
|
||||||
bwipe
|
bwipe
|
||||||
|
|
||||||
|
call assert_fails("call term_start(cmd, {'term_opencmd': 'open'})", 'E475:')
|
||||||
|
call assert_fails("call term_start(cmd, {'term_opencmd': 'split %x'})", 'E475:')
|
||||||
|
call assert_fails("call term_start(cmd, {'term_opencmd': 'split %d and %s'})", 'E475:')
|
||||||
|
call assert_fails("call term_start(cmd, {'term_opencmd': 'split % and %d'})", 'E475:')
|
||||||
|
|
||||||
|
call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d'})
|
||||||
|
close
|
||||||
|
call WaitFor("winnr('$') == 2", waittime)
|
||||||
|
call assert_equal(2, winnr('$'))
|
||||||
|
call assert_equal(4, winheight(0))
|
||||||
|
bwipe
|
||||||
|
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_terminal_cwd()
|
func Test_terminal_cwd()
|
||||||
|
@@ -769,6 +769,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
916,
|
||||||
/**/
|
/**/
|
||||||
915,
|
915,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user