To reproduce: vim --clean :set nomodifiable yy p
Note the duplicate error message. Using ":put" this does not happen because the command's MODIFY flag catches the problem early. Two tests are included. One of them will currently fail. The other is just for additional error checking and practice. Thanks, Jason Franklin -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
>From 47bb908693eb4d14652e21243cdc415b62c83d8a Mon Sep 17 00:00:00 2001 From: Jason Franklin <[email protected]> Date: Tue, 26 Jun 2018 09:32:10 -0400 Subject: [PATCH] Fix duplicate errmsg from Normal mode "p" command --- src/ops.c | 7 ++--- src/testdir/test_messages.vim | 2 +- src/testdir/test_put.vim | 48 +++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/ops.c b/src/ops.c index 2dbc74889..73f73d2f9 100644 --- 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) { diff --git a/src/testdir/test_messages.vim b/src/testdir/test_messages.vim index 384d2aa94..a85799e26 100644 --- 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. diff --git a/src/testdir/test_put.vim b/src/testdir/test_put.vim index 0a23a4391..078ef4430 100644 --- 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,50 @@ 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 + + set nomodifiable& + 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")) + + set nomodifiable& + bwipeout! +endfunc -- 2.17.1
