Patch 8.1.1061
Problem:    When substitute string throws error, substitute happens anyway.
Solution:   Skip substitution when aborting. (closes #4161)
Files:      src/ex_cmds.c, src/testdir/test_substitute.vim


*** ../vim-8.1.1060/src/ex_cmds.c       2019-03-17 16:59:38.582201903 +0100
--- src/ex_cmds.c       2019-03-24 22:26:56.525595616 +0100
***************
*** 5574,5580 ****
                                    sub_firstlnum - regmatch.startpos[0].lnum,
                                    sub, sub_firstline, FALSE, p_magic, TRUE);
  #ifdef FEAT_EVAL
!               /* Don't keep flags set by a recursive call. */
                subflags = subflags_save;
                if (subflags.do_count)
                {
--- 5574,5585 ----
                                    sub_firstlnum - regmatch.startpos[0].lnum,
                                    sub, sub_firstline, FALSE, p_magic, TRUE);
  #ifdef FEAT_EVAL
!               // If getting the substitute string caused an error, don't do
!               // the replacement.
!               if (aborting())
!                   goto skip;
! 
!               // Don't keep flags set by a recursive call.
                subflags = subflags_save;
                if (subflags.do_count)
                {
*** ../vim-8.1.1060/src/testdir/test_substitute.vim     2019-02-10 
22:50:08.011856775 +0100
--- src/testdir/test_substitute.vim     2019-03-27 22:33:23.761578469 +0100
***************
*** 610,612 ****
--- 610,642 ----
    enew!
    set titlestring&
  endfunc
+ 
+ func Test_nocatch_sub_failure_handling()
+   " normal error results in all replacements 
+   func! Foo()
+     foobar
+   endfunc
+   new
+   call setline(1, ['1 aaa', '2 aaa', '3 aaa'])
+   %s/aaa/\=Foo()/g
+   call assert_equal(['1 0', '2 0', '3 0'], getline(1, 3))
+ 
+   " Trow without try-catch causes abort after the first line.
+   " We cannot test this, since it would stop executing the test script.
+ 
+   " try/catch does not result in any changes
+   func! Foo()
+     throw 'error'
+   endfunc
+   call setline(1, ['1 aaa', '2 aaa', '3 aaa'])
+   let error_caught = 0
+   try
+     %s/aaa/\=Foo()/g
+   catch
+     let error_caught = 1
+   endtry
+   call assert_equal(1, error_caught)
+   call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3))
+ 
+   bwipe!
+ endfunc
*** ../vim-8.1.1060/src/version.c       2019-03-27 21:59:40.903552946 +0100
--- src/version.c       2019-03-27 22:34:08.561183332 +0100
***************
*** 777,778 ****
--- 777,780 ----
  {   /* Add new patch number below this line */
+ /**/
+     1061,
  /**/

-- 
"The sun oozed over the horizon, shoved aside darkness, crept along the
greensward, and, with sickly fingers, pushed through the castle window,
revealing the pillaged princess, hand at throat, crown asunder, gaping
in frenzied horror at the sated, sodden amphibian lying beside her,
disbelieving the magnitude of the frog's deception, screaming madly,
"You lied!"
    - Winner of the Bulwer-Lytton contest (San Jose State University),
      wherein one writes only the first line of a bad novel

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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.

Raspunde prin e-mail lui