]> git.pld-linux.org Git - packages/vim.git/blob - 7.1.214
- typo
[packages/vim.git] / 7.1.214
1 To: vim-dev@vim.org
2 Subject: Patch 7.1.214
3 Fcc: outbox
4 From: Bram Moolenaar <Bram@moolenaar.net>
5 Mime-Version: 1.0
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
8 ------------
9
10 Patch 7.1.214
11 Problem:    ":1s/g\n\zs1//" deletes characters from the first line. (A Politz)
12 Solution:   Start replacing in the line where the match starts.
13 Files:      src/ex_cmds.c
14
15
16 *** ../vim-7.1.213/src/ex_cmds.c        Fri Jan  4 14:52:14 2008
17 --- src/ex_cmds.c       Wed Jan  9 22:32:26 2008
18 ***************
19 *** 4200,4206 ****
20       linenr_T  old_line_count = curbuf->b_ml.ml_line_count;
21       linenr_T  line2;
22       long      nmatch;                 /* number of lines in match */
23 -     linenr_T  sub_firstlnum;          /* nr of first sub line */
24       char_u    *sub_firstline;         /* allocated copy of first sub line */
25       int               endcolumn = FALSE;      /* cursor in last column when done */
26       pos_T     old_cursor = curwin->w_cursor;
27 --- 4200,4205 ----
28 ***************
29 *** 4447,4453 ****
30   #endif
31                 ); ++lnum)
32       {
33 -       sub_firstlnum = lnum;
34         nmatch = vim_regexec_multi(&regmatch, curwin, curbuf, lnum, (colnr_T)0);
35         if (nmatch)
36         {
37 --- 4446,4451 ----
38 ***************
39 *** 4463,4468 ****
40 --- 4461,4467 ----
41             long        nmatch_tl = 0;  /* nr of lines matched below lnum */
42             int         do_again;       /* do it again after joining lines */
43             int         skip_match = FALSE;
44 +           linenr_T    sub_firstlnum;  /* nr of first sub line */
45   
46             /*
47              * The new text is build up step by step, to avoid too much
48 ***************
49 *** 4482,4489 ****
50              *                  far.
51              * new_end          The new text, where to append new text.
52              *
53 !            * lnum             The line number where we were looking for the
54 !            *                  first match in the old line.
55              * sub_firstlnum    The line number in the buffer where to look
56              *                  for a match.  Can be different from "lnum"
57              *                  when the pattern or substitute string contains
58 --- 4481,4490 ----
59              *                  far.
60              * new_end          The new text, where to append new text.
61              *
62 !            * lnum             The line number where we found the start of
63 !            *                  the match.  Can be below the line we searched
64 !            *                  when there is a \n before a \zs in the
65 !            *                  pattern.
66              * sub_firstlnum    The line number in the buffer where to look
67              *                  for a match.  Can be different from "lnum"
68              *                  when the pattern or substitute string contains
69 ***************
70 *** 4507,4518 ****
71              * updating the screen or handling a multi-line match.  The "old_"
72              * pointers point into this copy.
73              */
74 !           sub_firstline = vim_strsave(ml_get(sub_firstlnum));
75 !           if (sub_firstline == NULL)
76 !           {
77 !               vim_free(new_start);
78 !               goto outofmem;
79 !           }
80             copycol = 0;
81             matchcol = 0;
82   
83 --- 4508,4514 ----
84              * updating the screen or handling a multi-line match.  The "old_"
85              * pointers point into this copy.
86              */
87 !           sub_firstlnum = lnum;
88             copycol = 0;
89             matchcol = 0;
90   
91 ***************
92 *** 4533,4538 ****
93 --- 4529,4556 ----
94              */
95             for (;;)
96             {
97 +               /* Advance "lnum" to the line where the match starts.  The
98 +                * match does not start in the first line when there is a line
99 +                * break before \zs. */
100 +               if (regmatch.startpos[0].lnum > 0)
101 +               {
102 +                   lnum += regmatch.startpos[0].lnum;
103 +                   sub_firstlnum += regmatch.startpos[0].lnum;
104 +                   nmatch -= regmatch.startpos[0].lnum;
105 +                   vim_free(sub_firstline);
106 +                   sub_firstline = NULL;
107 +               }
108
109 +               if (sub_firstline == NULL)
110 +               {
111 +                   sub_firstline = vim_strsave(ml_get(sub_firstlnum));
112 +                   if (sub_firstline == NULL)
113 +                   {
114 +                       vim_free(new_start);
115 +                       goto outofmem;
116 +                   }
117 +               }
118
119                 /* Save the line number of the last change for the final
120                  * cursor position (just like Vi). */
121                 curwin->w_cursor.lnum = lnum;
122 ***************
123 *** 4638,4644 ****
124                             temp = RedrawingDisabled;
125                             RedrawingDisabled = 0;
126   
127 !                           search_match_lines = regmatch.endpos[0].lnum;
128                             search_match_endcol = regmatch.endpos[0].col;
129                             highlight_match = TRUE;
130   
131 --- 4656,4663 ----
132                             temp = RedrawingDisabled;
133                             RedrawingDisabled = 0;
134   
135 !                           search_match_lines = regmatch.endpos[0].lnum
136 !                                                 - regmatch.startpos[0].lnum;
137                             search_match_endcol = regmatch.endpos[0].col;
138                             highlight_match = TRUE;
139   
140 ***************
141 *** 4749,4755 ****
142                  * 3. substitute the string.
143                  */
144                 /* get length of substitution part */
145 !               sublen = vim_regsub_multi(&regmatch, sub_firstlnum,
146                                     sub, sub_firstline, FALSE, p_magic, TRUE);
147   
148                 /* When the match included the "$" of the last line it may
149 --- 4768,4775 ----
150                  * 3. substitute the string.
151                  */
152                 /* get length of substitution part */
153 !               sublen = vim_regsub_multi(&regmatch,
154 !                                   sub_firstlnum - regmatch.startpos[0].lnum,
155                                     sub, sub_firstline, FALSE, p_magic, TRUE);
156   
157                 /* When the match included the "$" of the last line it may
158 ***************
159 *** 4819,4825 ****
160                 mch_memmove(new_end, sub_firstline + copycol, (size_t)i);
161                 new_end += i;
162   
163 !               (void)vim_regsub_multi(&regmatch, sub_firstlnum,
164                                            sub, new_end, TRUE, p_magic, TRUE);
165                 sub_nsubs++;
166                 did_sub = TRUE;
167 --- 4839,4846 ----
168                 mch_memmove(new_end, sub_firstline + copycol, (size_t)i);
169                 new_end += i;
170   
171 !               (void)vim_regsub_multi(&regmatch,
172 !                                   sub_firstlnum - regmatch.startpos[0].lnum,
173                                            sub, new_end, TRUE, p_magic, TRUE);
174                 sub_nsubs++;
175                 did_sub = TRUE;
176 ***************
177 *** 4908,4917 ****
178   skip:
179                 /* We already know that we did the last subst when we are at
180                  * the end of the line, except that a pattern like
181 !                * "bar\|\nfoo" may match at the NUL. */
182                 lastone = (skip_match
183                         || got_int
184                         || got_quit
185                         || !(do_all || do_again)
186                         || (sub_firstline[matchcol] == NUL && nmatch <= 1
187                                          && !re_multiline(regmatch.regprog)));
188 --- 4929,4941 ----
189   skip:
190                 /* We already know that we did the last subst when we are at
191                  * the end of the line, except that a pattern like
192 !                * "bar\|\nfoo" may match at the NUL.  "lnum" can be below
193 !                * "line2" when there is a \zs in the pattern after a line
194 !                * break. */
195                 lastone = (skip_match
196                         || got_int
197                         || got_quit
198 +                       || lnum > line2
199                         || !(do_all || do_again)
200                         || (sub_firstline[matchcol] == NUL && nmatch <= 1
201                                          && !re_multiline(regmatch.regprog)));
202 ***************
203 *** 4926,4937 ****
204                  * When asking the user we like to show the already replaced
205                  * text, but don't do it when "\<@=" or "\<@!" is used, it
206                  * changes what matches.
207                  */
208                 if (lastone
209                         || (do_ask && !re_lookbehind(regmatch.regprog))
210                         || nmatch_tl > 0
211                         || (nmatch = vim_regexec_multi(&regmatch, curwin,
212 !                                      curbuf, sub_firstlnum, matchcol)) == 0)
213                 {
214                     if (new_start != NULL)
215                     {
216 --- 4950,4964 ----
217                  * When asking the user we like to show the already replaced
218                  * text, but don't do it when "\<@=" or "\<@!" is used, it
219                  * changes what matches.
220 +                * When the match starts below where we start searching also
221 +                * need to replace the line first (using \zs after \n).
222                  */
223                 if (lastone
224                         || (do_ask && !re_lookbehind(regmatch.regprog))
225                         || nmatch_tl > 0
226                         || (nmatch = vim_regexec_multi(&regmatch, curwin,
227 !                                      curbuf, sub_firstlnum, matchcol)) == 0
228 !                       || regmatch.startpos[0].lnum > 0)
229                 {
230                     if (new_start != NULL)
231                     {
232 ***************
233 *** 5001,5007 ****
234 --- 5028,5041 ----
235                      * 5. break if there isn't another match in this line
236                      */
237                     if (nmatch <= 0)
238 +                   {
239 +                       /* If the match found didn't start where we were
240 +                        * searching, do the next search in the line where we
241 +                        * found the match. */
242 +                       if (nmatch == -1)
243 +                           lnum -= regmatch.startpos[0].lnum;
244                         break;
245 +                   }
246                 }
247   
248                 line_breakcheck();
249 *** ../vim-7.1.213/src/version.c        Wed Jan  9 20:29:51 2008
250 --- src/version.c       Wed Jan  9 22:37:47 2008
251 ***************
252 *** 668,669 ****
253 --- 668,671 ----
254   {   /* Add new patch number below this line */
255 + /**/
256 +     214,
257   /**/
258
259 -- 
260 Q: What's orange and sounds like a parrot?
261 A: A carrot
262
263  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
264 ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
265 \\\        download, build and distribute -- http://www.A-A-P.org        ///
266  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
This page took 0.059603 seconds and 3 git commands to generate.