changeset 23893:a433d0070c45 v8.2.2489

patch 8.2.2489: current buffer is wrong after deletebufline() fails Commit: https://github.com/vim/vim/commit/963ffa0a5a6091655ed72b4590ec5d5a1653bce8 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Feb 9 20:02:55 2021 +0100 patch 8.2.2489: current buffer is wrong after deletebufline() fails Problem: current buffer is wrong after deletebufline() fails to delete a line in another buffer. Solution: Restore the current buffer.
author Bram Moolenaar <Bram@vim.org>
date Tue, 09 Feb 2021 20:15:04 +0100
parents ca2346d6d6f1
children 543007252974
files src/evalbuffer.c src/testdir/test_bufline.vim src/version.c
diffstat 3 files changed, 30 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/evalbuffer.c
+++ b/src/evalbuffer.c
@@ -500,24 +500,25 @@ f_deletebufline(typval_T *argvars, typva
     if (u_save(first - 1, last + 1) == FAIL)
     {
 	rettv->vval.v_number = 1;	// FAIL
-	return;
     }
-
-    for (lnum = first; lnum <= last; ++lnum)
-	ml_delete_flags(first, ML_DEL_MESSAGE);
+    else
+    {
+	for (lnum = first; lnum <= last; ++lnum)
+	    ml_delete_flags(first, ML_DEL_MESSAGE);
 
-    FOR_ALL_TAB_WINDOWS(tp, wp)
-	if (wp->w_buffer == buf)
-	{
-	    if (wp->w_cursor.lnum > last)
-		wp->w_cursor.lnum -= count;
-	    else if (wp->w_cursor.lnum> first)
-		wp->w_cursor.lnum = first;
-	    if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count)
-		wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count;
-	}
-    check_cursor_col();
-    deleted_lines_mark(first, count);
+	FOR_ALL_TAB_WINDOWS(tp, wp)
+	    if (wp->w_buffer == buf)
+	    {
+		if (wp->w_cursor.lnum > last)
+		    wp->w_cursor.lnum -= count;
+		else if (wp->w_cursor.lnum> first)
+		    wp->w_cursor.lnum = first;
+		if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count)
+		    wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count;
+	    }
+	check_cursor_col();
+	deleted_lines_mark(first, count);
+    }
 
     if (!is_curbuf)
     {
--- a/src/testdir/test_bufline.vim
+++ b/src/testdir/test_bufline.vim
@@ -186,6 +186,17 @@ func Test_deletebufline()
   call assert_equal(0, deletebufline(b, 1))
   call assert_equal(['b', 'c'], getbufline(b, 1, 2))
   exe "bwipe! " . b
+
+  edit XbufOne
+  let one = bufnr()
+  call setline(1, ['a', 'b', 'c'])
+  setlocal nomodifiable
+  split XbufTwo
+  let two = bufnr()
+  call assert_fails('call deletebufline(one, 1)', 'E21:')
+  call assert_equal(two, bufnr())
+  bwipe! XbufTwo
+  bwipe! XbufOne
 endfunc
 
 func Test_appendbufline_redraw()
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2489,
+/**/
     2488,
 /**/
     2487,