1 To: [email protected] |
|
2 Subject: Patch 7.2.308 |
|
3 Fcc: outbox |
|
4 From: Bram Moolenaar <[email protected]> |
|
5 Mime-Version: 1.0 |
|
6 Content-Type: text/plain; charset=UTF-8 |
|
7 Content-Transfer-Encoding: 8bit |
|
8 ------------ |
|
9 |
|
10 Patch 7.2.308 |
|
11 Problem: When using a regexp in the "\=" expression of a substitute |
|
12 command, submatch() returns empty strings for further lines. |
|
13 (Clockwork Jam) |
|
14 Solution: Save and restore the line number and line count when calling |
|
15 reg_getline(). |
|
16 Files: src/regexp.c |
|
17 |
|
18 |
|
19 *** ../vim-7.2.307/src/regexp.c 2009-11-25 18:21:48.000000000 +0100 |
|
20 --- src/regexp.c 2009-11-25 19:45:07.000000000 +0100 |
|
21 *************** |
|
22 *** 6828,6833 **** |
|
23 --- 6828,6835 ---- |
|
24 * that contains a call to substitute() and submatch(). */ |
|
25 static regmatch_T *submatch_match; |
|
26 static regmmatch_T *submatch_mmatch; |
|
27 + static linenr_T submatch_firstlnum; |
|
28 + static linenr_T submatch_maxline; |
|
29 #endif |
|
30 |
|
31 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) || defined(PROTO) |
|
32 *************** |
|
33 *** 6941,6947 **** |
|
34 } |
|
35 else |
|
36 { |
|
37 - linenr_T save_reg_maxline; |
|
38 win_T *save_reg_win; |
|
39 int save_ireg_ic; |
|
40 |
|
41 --- 6943,6948 ---- |
|
42 *************** |
|
43 *** 6953,6959 **** |
|
44 * vim_regexec_multi() can't be called recursively. */ |
|
45 submatch_match = reg_match; |
|
46 submatch_mmatch = reg_mmatch; |
|
47 ! save_reg_maxline = reg_maxline; |
|
48 save_reg_win = reg_win; |
|
49 save_ireg_ic = ireg_ic; |
|
50 can_f_submatch = TRUE; |
|
51 --- 6954,6961 ---- |
|
52 * vim_regexec_multi() can't be called recursively. */ |
|
53 submatch_match = reg_match; |
|
54 submatch_mmatch = reg_mmatch; |
|
55 ! submatch_firstlnum = reg_firstlnum; |
|
56 ! submatch_maxline = reg_maxline; |
|
57 save_reg_win = reg_win; |
|
58 save_ireg_ic = ireg_ic; |
|
59 can_f_submatch = TRUE; |
|
60 *************** |
|
61 *** 6976,6982 **** |
|
62 |
|
63 reg_match = submatch_match; |
|
64 reg_mmatch = submatch_mmatch; |
|
65 ! reg_maxline = save_reg_maxline; |
|
66 reg_win = save_reg_win; |
|
67 ireg_ic = save_ireg_ic; |
|
68 can_f_submatch = FALSE; |
|
69 --- 6978,6985 ---- |
|
70 |
|
71 reg_match = submatch_match; |
|
72 reg_mmatch = submatch_mmatch; |
|
73 ! reg_firstlnum = submatch_firstlnum; |
|
74 ! reg_maxline = submatch_maxline; |
|
75 reg_win = save_reg_win; |
|
76 ireg_ic = save_ireg_ic; |
|
77 can_f_submatch = FALSE; |
|
78 *************** |
|
79 *** 7212,7217 **** |
|
80 --- 7215,7243 ---- |
|
81 |
|
82 #ifdef FEAT_EVAL |
|
83 /* |
|
84 + * Call reg_getline() with the line numbers from the submatch. If a |
|
85 + * substitute() was used the reg_maxline and other values have been |
|
86 + * overwritten. |
|
87 + */ |
|
88 + static char_u * |
|
89 + reg_getline_submatch(lnum) |
|
90 + linenr_T lnum; |
|
91 + { |
|
92 + char_u *s; |
|
93 + linenr_T save_first = reg_firstlnum; |
|
94 + linenr_T save_max = reg_maxline; |
|
95 + |
|
96 + reg_firstlnum = submatch_firstlnum; |
|
97 + reg_maxline = submatch_maxline; |
|
98 + |
|
99 + s = reg_getline(lnum); |
|
100 + |
|
101 + reg_firstlnum = save_first; |
|
102 + reg_maxline = save_max; |
|
103 + return s; |
|
104 + } |
|
105 + |
|
106 + /* |
|
107 * Used for the submatch() function: get the string from the n'th submatch in |
|
108 * allocated memory. |
|
109 * Returns NULL when not in a ":s" command and for a non-existing submatch. |
|
110 *************** |
|
111 *** 7241,7247 **** |
|
112 if (lnum < 0 || submatch_mmatch->endpos[no].lnum < 0) |
|
113 return NULL; |
|
114 |
|
115 ! s = reg_getline(lnum) + submatch_mmatch->startpos[no].col; |
|
116 if (s == NULL) /* anti-crash check, cannot happen? */ |
|
117 break; |
|
118 if (submatch_mmatch->endpos[no].lnum == lnum) |
|
119 --- 7267,7273 ---- |
|
120 if (lnum < 0 || submatch_mmatch->endpos[no].lnum < 0) |
|
121 return NULL; |
|
122 |
|
123 ! s = reg_getline_submatch(lnum) + submatch_mmatch->startpos[no].col; |
|
124 if (s == NULL) /* anti-crash check, cannot happen? */ |
|
125 break; |
|
126 if (submatch_mmatch->endpos[no].lnum == lnum) |
|
127 *************** |
|
128 *** 7267,7273 **** |
|
129 ++lnum; |
|
130 while (lnum < submatch_mmatch->endpos[no].lnum) |
|
131 { |
|
132 ! s = reg_getline(lnum++); |
|
133 if (round == 2) |
|
134 STRCPY(retval + len, s); |
|
135 len += (int)STRLEN(s); |
|
136 --- 7293,7299 ---- |
|
137 ++lnum; |
|
138 while (lnum < submatch_mmatch->endpos[no].lnum) |
|
139 { |
|
140 ! s = reg_getline_submatch(lnum++); |
|
141 if (round == 2) |
|
142 STRCPY(retval + len, s); |
|
143 len += (int)STRLEN(s); |
|
144 *************** |
|
145 *** 7276,7282 **** |
|
146 ++len; |
|
147 } |
|
148 if (round == 2) |
|
149 ! STRNCPY(retval + len, reg_getline(lnum), |
|
150 submatch_mmatch->endpos[no].col); |
|
151 len += submatch_mmatch->endpos[no].col; |
|
152 if (round == 2) |
|
153 --- 7302,7308 ---- |
|
154 ++len; |
|
155 } |
|
156 if (round == 2) |
|
157 ! STRNCPY(retval + len, reg_getline_submatch(lnum), |
|
158 submatch_mmatch->endpos[no].col); |
|
159 len += submatch_mmatch->endpos[no].col; |
|
160 if (round == 2) |
|
161 *** ../vim-7.2.307/src/version.c 2009-11-25 18:21:48.000000000 +0100 |
|
162 --- src/version.c 2009-11-25 19:50:16.000000000 +0100 |
|
163 *************** |
|
164 *** 683,684 **** |
|
165 --- 683,686 ---- |
|
166 { /* Add new patch number below this line */ |
|
167 + /**/ |
|
168 + 308, |
|
169 /**/ |
|
170 |
|
171 -- |
|
172 Engineers are always delighted to share wisdom, even in areas in which they |
|
173 have no experience whatsoever. Their logic provides them with inherent |
|
174 insight into any field of expertise. This can be a problem when dealing with |
|
175 the illogical people who believe that knowledge can only be derived through |
|
176 experience. |
|
177 (Scott Adams - The Dilbert principle) |
|
178 |
|
179 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\ |
|
180 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ |
|
181 \\\ download, build and distribute -- http://www.A-A-P.org /// |
|
182 \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |
|