diff src/terminal.c @ 16912:a5e3509b33ca v8.1.1457

patch 8.1.1457: cannot reuse a buffer when loading a screen dump commit https://github.com/vim/vim/commit/87abab92f5b42319a7b10df9974ed3ce5c9b2b9b Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jun 3 21:14:59 2019 +0200 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.
author Bram Moolenaar <Bram@vim.org>
date Mon, 03 Jun 2019 21:30:05 +0200
parents ce04ebdf26b8
children 2a9a5e69fb3e
line wrap: on
line diff
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -4616,7 +4616,7 @@ get_separator(int text_width, char_u *fn
 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
 	}
     }
 
-    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;