summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.1061
blob: c826568216bad5a94496f46367a8d6ea76bfdc45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
To: vim_dev@googlegroups.com
Subject: Patch 8.1.1061
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

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 -- Bram@Moolenaar.net -- 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    ///