changeset 14202:51693b1a640e v8.1.0118

patch 8.1.0118: duplicate error message for put command commit https://github.com/vim/vim/commit/f52f9ea8f5fb3df51a308c56f2bf66f735ef3ca7 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jun 27 20:49:44 2018 +0200 patch 8.1.0118: duplicate error message for put command Problem: Duplicate error message for put command. Solution: Check return value of u_save(). (Jason Franklin)
author Christian Brabandt <cb@256bit.org>
date Wed, 27 Jun 2018 21:00:07 +0200
parents d0e504f050f0
children f5c110d0bb26
files src/ops.c src/testdir/test_messages.vim src/testdir/test_put.vim src/version.c
diffstat 4 files changed, 53 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/ops.c
+++ b/src/ops.c
@@ -3551,9 +3551,10 @@ do_put(
 	    return;
     }
 
-    /* Autocommands may be executed when saving lines for undo, which may make
-     * y_array invalid.  Start undo now to avoid that. */
-    u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1);
+    /* Autocommands may be executed when saving lines for undo.  This might
+     * make "y_array" invalid, so we start undo now to avoid that. */
+    if (u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1) == FAIL)
+	goto end;
 
     if (insert_string != NULL)
     {
--- a/src/testdir/test_messages.vim
+++ b/src/testdir/test_messages.vim
@@ -39,7 +39,7 @@ function Test_messages()
   endtry
 endfunction
 
-" Patch 7.4.1696 defined the "clearmode()" command for clearing the mode
+" Patch 7.4.1696 defined the "clearmode()" function for clearing the mode
 " indicator (e.g., "-- INSERT --") when ":stopinsert" is invoked.  Message
 " output could then be disturbed when 'cmdheight' was greater than one.
 " This test ensures that the bugfix for this issue remains in place.
--- a/src/testdir/test_put.vim
+++ b/src/testdir/test_put.vim
@@ -1,3 +1,4 @@
+" Tests for put commands, e.g. ":put", "p", "gp", "P", "gP", etc.
 
 func Test_put_block()
   if !has('multi_byte')
@@ -58,3 +59,48 @@ func Test_put_expr()
   call assert_equal(['A1','A2','A3','4A','5A','6A'], getline(1,'$'))
   bw!
 endfunc
+
+func Test_put_fails_when_nomodifiable()
+  new
+  set nomodifiable
+
+  normal! yy
+  call assert_fails(':put', 'E21')
+  call assert_fails(':put!', 'E21')
+  call assert_fails(':normal! p', 'E21')
+  call assert_fails(':normal! gp', 'E21')
+  call assert_fails(':normal! P', 'E21')
+  call assert_fails(':normal! gP', 'E21')
+
+  if has('mouse')
+    set mouse=n
+    call assert_fails('execute "normal! \<MiddleMouse>"', 'E21')
+    set mouse&
+  endif
+
+  bwipeout!
+endfunc
+
+" A bug was discovered where the Normal mode put commands (e.g., "p") would
+" output duplicate error messages when invoked in a non-modifiable buffer.
+func Test_put_p_errmsg_nodup()
+  new
+  set nomodifiable
+
+  normal! yy
+
+  func Capture_p_error()
+    redir => s:p_err
+    normal! p
+    redir END
+  endfunc
+
+  silent! call Capture_p_error()
+
+  " Error message output within a function should be three lines (the function
+  " name, the line number, and the error message).
+  call assert_equal(3, count(s:p_err, "\n"))
+
+  delfunction Capture_p_error
+  bwipeout!
+endfunc
--- a/src/version.c
+++ b/src/version.c
@@ -790,6 +790,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    118,
+/**/
     117,
 /**/
     116,