summaryrefslogtreecommitdiffstats
path: root/gvim/vim-7.2/7.2.308
blob: 1e19b21dcc92ba0ddf15dc1fd848cb97e2115f91 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
To: vim-dev@vim.org
Subject: Patch 7.2.308
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.2.308
Problem:    When using a regexp in the "\=" expression of a substitute
	    command, submatch() returns empty strings for further lines.
	    (Clockwork Jam)
Solution:   Save and restore the line number and line count when calling
	    reg_getline().
Files:	    src/regexp.c


*** ../vim-7.2.307/src/regexp.c	2009-11-25 18:21:48.000000000 +0100
--- src/regexp.c	2009-11-25 19:45:07.000000000 +0100
***************
*** 6828,6833 ****
--- 6828,6835 ----
   * that contains a call to substitute() and submatch(). */
  static regmatch_T	*submatch_match;
  static regmmatch_T	*submatch_mmatch;
+ static linenr_T		submatch_firstlnum;
+ static linenr_T		submatch_maxline;
  #endif
  
  #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) || defined(PROTO)
***************
*** 6941,6947 ****
  	}
  	else
  	{
- 	    linenr_T	save_reg_maxline;
  	    win_T	*save_reg_win;
  	    int		save_ireg_ic;
  
--- 6943,6948 ----
***************
*** 6953,6959 ****
  	     * vim_regexec_multi() can't be called recursively. */
  	    submatch_match = reg_match;
  	    submatch_mmatch = reg_mmatch;
! 	    save_reg_maxline = reg_maxline;
  	    save_reg_win = reg_win;
  	    save_ireg_ic = ireg_ic;
  	    can_f_submatch = TRUE;
--- 6954,6961 ----
  	     * vim_regexec_multi() can't be called recursively. */
  	    submatch_match = reg_match;
  	    submatch_mmatch = reg_mmatch;
! 	    submatch_firstlnum = reg_firstlnum;
! 	    submatch_maxline = reg_maxline;
  	    save_reg_win = reg_win;
  	    save_ireg_ic = ireg_ic;
  	    can_f_submatch = TRUE;
***************
*** 6976,6982 ****
  
  	    reg_match = submatch_match;
  	    reg_mmatch = submatch_mmatch;
! 	    reg_maxline = save_reg_maxline;
  	    reg_win = save_reg_win;
  	    ireg_ic = save_ireg_ic;
  	    can_f_submatch = FALSE;
--- 6978,6985 ----
  
  	    reg_match = submatch_match;
  	    reg_mmatch = submatch_mmatch;
! 	    reg_firstlnum = submatch_firstlnum;
! 	    reg_maxline = submatch_maxline;
  	    reg_win = save_reg_win;
  	    ireg_ic = save_ireg_ic;
  	    can_f_submatch = FALSE;
***************
*** 7212,7217 ****
--- 7215,7243 ----
  
  #ifdef FEAT_EVAL
  /*
+  * Call reg_getline() with the line numbers from the submatch.  If a
+  * substitute() was used the reg_maxline and other values have been
+  * overwritten.
+  */
+     static char_u *
+ reg_getline_submatch(lnum)
+     linenr_T	lnum;
+ {
+     char_u *s;
+     linenr_T save_first = reg_firstlnum;
+     linenr_T save_max = reg_maxline;
+ 
+     reg_firstlnum = submatch_firstlnum;
+     reg_maxline = submatch_maxline;
+ 
+     s = reg_getline(lnum);
+ 
+     reg_firstlnum = save_first;
+     reg_maxline = save_max;
+     return s;
+ }
+ 
+ /*
   * Used for the submatch() function: get the string from the n'th submatch in
   * allocated memory.
   * Returns NULL when not in a ":s" command and for a non-existing submatch.
***************
*** 7241,7247 ****
  	    if (lnum < 0 || submatch_mmatch->endpos[no].lnum < 0)
  		return NULL;
  
! 	    s = reg_getline(lnum) + submatch_mmatch->startpos[no].col;
  	    if (s == NULL)  /* anti-crash check, cannot happen? */
  		break;
  	    if (submatch_mmatch->endpos[no].lnum == lnum)
--- 7267,7273 ----
  	    if (lnum < 0 || submatch_mmatch->endpos[no].lnum < 0)
  		return NULL;
  
! 	    s = reg_getline_submatch(lnum) + submatch_mmatch->startpos[no].col;
  	    if (s == NULL)  /* anti-crash check, cannot happen? */
  		break;
  	    if (submatch_mmatch->endpos[no].lnum == lnum)
***************
*** 7267,7273 ****
  		++lnum;
  		while (lnum < submatch_mmatch->endpos[no].lnum)
  		{
! 		    s = reg_getline(lnum++);
  		    if (round == 2)
  			STRCPY(retval + len, s);
  		    len += (int)STRLEN(s);
--- 7293,7299 ----
  		++lnum;
  		while (lnum < submatch_mmatch->endpos[no].lnum)
  		{
! 		    s = reg_getline_submatch(lnum++);
  		    if (round == 2)
  			STRCPY(retval + len, s);
  		    len += (int)STRLEN(s);
***************
*** 7276,7282 ****
  		    ++len;
  		}
  		if (round == 2)
! 		    STRNCPY(retval + len, reg_getline(lnum),
  					     submatch_mmatch->endpos[no].col);
  		len += submatch_mmatch->endpos[no].col;
  		if (round == 2)
--- 7302,7308 ----
  		    ++len;
  		}
  		if (round == 2)
! 		    STRNCPY(retval + len, reg_getline_submatch(lnum),
  					     submatch_mmatch->endpos[no].col);
  		len += submatch_mmatch->endpos[no].col;
  		if (round == 2)
*** ../vim-7.2.307/src/version.c	2009-11-25 18:21:48.000000000 +0100
--- src/version.c	2009-11-25 19:50:16.000000000 +0100
***************
*** 683,684 ****
--- 683,686 ----
  {   /* Add new patch number below this line */
+ /**/
+     308,
  /**/

-- 
Engineers are always delighted to share wisdom, even in areas in which they
have no experience whatsoever.  Their logic provides them with inherent
insight into any field of expertise.  This can be a problem when dealing with
the illogical people who believe that knowledge can only be derived through
experience.
				(Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///