mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.1.1457: cannot reuse a buffer when loading a screen dump
Problem: Cannot reuse a buffer when loading a screen dump. Solution: Add the "bufnr" option.
This commit is contained in:
@@ -9558,6 +9558,11 @@ term_dumpdiff({filename}, {filename} [, {options}])
|
||||
"curwin" use the current window, do not split the
|
||||
window; fails if the current buffer
|
||||
cannot be |abandon|ed
|
||||
"bufnr" do not create a new buffer, use the
|
||||
existing buffer "bufnr". This buffer
|
||||
must have been previously created with
|
||||
term_dumpdiff() or term_dumpload() and
|
||||
visible in a window.
|
||||
"norestore" do not add the terminal window to a
|
||||
session file
|
||||
|
||||
|
@@ -4901,6 +4901,32 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2)
|
||||
opt->jo_set2 |= JO2_CURWIN;
|
||||
opt->jo_curwin = tv_get_number(item);
|
||||
}
|
||||
else if (STRCMP(hi->hi_key, "bufnr") == 0)
|
||||
{
|
||||
int nr;
|
||||
|
||||
if (!(supported2 & JO2_CURWIN))
|
||||
break;
|
||||
opt->jo_set2 |= JO2_BUFNR;
|
||||
nr = tv_get_number(item);
|
||||
if (nr <= 0)
|
||||
{
|
||||
semsg(_(e_invargNval), hi->hi_key, tv_get_string(item));
|
||||
return FAIL;
|
||||
}
|
||||
opt->jo_bufnr_buf = buflist_findnr(nr);
|
||||
if (opt->jo_bufnr_buf == NULL)
|
||||
{
|
||||
semsg(_(e_nobufnr), (long)nr);
|
||||
return FAIL;
|
||||
}
|
||||
if (opt->jo_bufnr_buf->b_nwindows == 0
|
||||
|| opt->jo_bufnr_buf->b_term == NULL)
|
||||
{
|
||||
semsg(_(e_invarg2), "bufnr");
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
else if (STRCMP(hi->hi_key, "hidden") == 0)
|
||||
{
|
||||
if (!(supported2 & JO2_HIDDEN))
|
||||
|
@@ -1807,6 +1807,7 @@ struct channel_S {
|
||||
#define JO2_TERM_KILL 0x4000 /* "term_kill" */
|
||||
#define JO2_ANSI_COLORS 0x8000 /* "ansi_colors" */
|
||||
#define JO2_TTY_TYPE 0x10000 /* "tty_type" */
|
||||
#define JO2_BUFNR 0x20000 /* "bufnr" */
|
||||
|
||||
#define JO_MODE_ALL (JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE)
|
||||
#define JO_CB_ALL \
|
||||
@@ -1864,6 +1865,7 @@ typedef struct
|
||||
int jo_term_cols;
|
||||
int jo_vertical;
|
||||
int jo_curwin;
|
||||
buf_T *jo_bufnr_buf;
|
||||
int jo_hidden;
|
||||
int jo_term_norestore;
|
||||
char_u *jo_term_name;
|
||||
|
@@ -4616,7 +4616,7 @@ get_separator(int text_width, char_u *fname)
|
||||
term_load_dump(typval_T *argvars, typval_T *rettv, int do_diff)
|
||||
{
|
||||
jobopt_T opt;
|
||||
buf_T *buf;
|
||||
buf_T *buf = NULL;
|
||||
char_u buf1[NUMBUFLEN];
|
||||
char_u buf2[NUMBUFLEN];
|
||||
char_u *fname1;
|
||||
@@ -4671,7 +4671,27 @@ term_load_dump(typval_T *argvars, typval_T *rettv, int do_diff)
|
||||
}
|
||||
}
|
||||
|
||||
if (opt.jo_bufnr_buf != NULL)
|
||||
{
|
||||
win_T *wp = buf_jump_open_win(opt.jo_bufnr_buf);
|
||||
|
||||
// With "bufnr" argument: enter the window with this buffer and make it
|
||||
// empty.
|
||||
if (wp == NULL)
|
||||
semsg(_(e_invarg2), "bufnr");
|
||||
else
|
||||
{
|
||||
buf = curbuf;
|
||||
while (!(curbuf->b_ml.ml_flags & ML_EMPTY))
|
||||
ml_delete((linenr_T)1, FALSE);
|
||||
ga_clear(&curbuf->b_term->tl_scrollback);
|
||||
redraw_later(NOT_VALID);
|
||||
}
|
||||
}
|
||||
else
|
||||
// Create a new terminal window.
|
||||
buf = term_start(&argvars[0], NULL, &opt, TERM_START_NOJOB);
|
||||
|
||||
if (buf != NULL && buf->b_term != NULL)
|
||||
{
|
||||
int i;
|
||||
|
@@ -1119,11 +1119,30 @@ endfunc
|
||||
|
||||
" just testing basic functionality.
|
||||
func Test_terminal_dumpload()
|
||||
let curbuf = winbufnr('')
|
||||
call assert_equal(1, winnr('$'))
|
||||
call term_dumpload('dumps/Test_popup_command_01.dump')
|
||||
let buf = term_dumpload('dumps/Test_popup_command_01.dump')
|
||||
call assert_equal(2, winnr('$'))
|
||||
call assert_equal(20, line('$'))
|
||||
call Check_dump01(0)
|
||||
|
||||
" Load another dump in the same window
|
||||
let buf2 = term_dumpload('dumps/Test_diff_01.dump', {'bufnr': buf})
|
||||
call assert_equal(buf, buf2)
|
||||
call assert_notequal('one two three four five', trim(getline(1)))
|
||||
|
||||
" Load the first dump again in the same window
|
||||
let buf2 = term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': buf})
|
||||
call assert_equal(buf, buf2)
|
||||
call Check_dump01(0)
|
||||
|
||||
call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': curbuf})", 'E475:')
|
||||
call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': 9999})", 'E86:')
|
||||
new
|
||||
let closedbuf = winbufnr('')
|
||||
quit
|
||||
call assert_fails("call term_dumpload('dumps/Test_popup_command_01.dump', {'bufnr': closedbuf})", 'E475:')
|
||||
|
||||
quit
|
||||
endfunc
|
||||
|
||||
|
@@ -767,6 +767,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1457,
|
||||
/**/
|
||||
1456,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user