]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.1.1457: cannot reuse a buffer when loading a screen dump v8.1.1457
authorBram Moolenaar <Bram@vim.org>
Mon, 3 Jun 2019 19:14:59 +0000 (21:14 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 3 Jun 2019 19:14:59 +0000 (21:14 +0200)
Problem:    Cannot reuse a buffer when loading a screen dump.
Solution:   Add the "bufnr" option.

runtime/doc/eval.txt
src/channel.c
src/structs.h
src/terminal.c
src/testdir/test_terminal.vim
src/version.c

index 844b68ef4cdcf01c4600d62695e9180f825442c6..c095d580c2c862a31b833431c9ee9a20d38872b1 100644 (file)
@@ -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
 
index 5ace0713d198118f35c55b426a80b254e22abba7..c9bfd3e332028bf6a868785012cb68bcd41151cc 100644 (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))
index bc1e4878605cf88062731fb95aebe2d6dd408d35..c68989aabfd29023b8ebfeaf5220dcfd5da481dc 100644 (file)
@@ -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;
index 2b964ae60ae0b0c9313c31cd1acf27c39fdc4223..1764b052d89beb255003968f2cdaffab88d18957 100644 (file)
@@ -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;
index 8139453563730461ae58e0797648b53b4b080b1a..b97cdb310abf55dbc95802b8f241db80eb6e9bf1 100644 (file)
@@ -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
 
index 29006c12c2fdc55dcfe7728770f2fd9e7a1918dc..f939ad8ca20ce6a95fdd7cd2780d48c6188f8cbc 100644 (file)
@@ -767,6 +767,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1457,
 /**/
     1456,
 /**/