summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-06-03 21:14:59 +0200
committerBram Moolenaar <Bram@vim.org>2019-06-03 21:14:59 +0200
commit87abab92f5b42319a7b10df9974ed3ce5c9b2b9b (patch)
treeab0b61854d1fc219eac955f66fe90a378484efb6
parent98fb65cb051f625f4ce291a9f9cdb2e54ac1e688 (diff)
downloadvim-git-87abab92f5b42319a7b10df9974ed3ce5c9b2b9b.tar.gz
patch 8.1.1457: cannot reuse a buffer when loading a screen dumpv8.1.1457
Problem: Cannot reuse a buffer when loading a screen dump. Solution: Add the "bufnr" option.
-rw-r--r--runtime/doc/eval.txt5
-rw-r--r--src/channel.c26
-rw-r--r--src/structs.h2
-rw-r--r--src/terminal.c24
-rw-r--r--src/testdir/test_terminal.vim21
-rw-r--r--src/version.c2
6 files changed, 77 insertions, 3 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 844b68ef4..c095d580c 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -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
diff --git a/src/channel.c b/src/channel.c
index 5ace0713d..c9bfd3e33 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -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))
diff --git a/src/structs.h b/src/structs.h
index bc1e48786..c68989aab 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -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;
diff --git a/src/terminal.c b/src/terminal.c
index 2b964ae60..1764b052d 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -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)
}
}
- buf = term_start(&argvars[0], NULL, &opt, TERM_START_NOJOB);
+ 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;
diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim
index 813945356..b97cdb310 100644
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index 29006c12c..f939ad8ca 100644
--- a/src/version.c
+++ b/src/version.c
@@ -768,6 +768,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1457,
+/**/
1456,
/**/
1455,