]>
Commit | Line | Data |
---|---|---|
d02ad552 AG |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 6.2.193 | |
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 6.2.193 | |
11 | Problem: When recalling a search pattern from the history from a ":s,a/c," | |
12 | command the '/' ends the search string. (JC van Winkel) | |
13 | Solution: Store the separator character with the history entries. Escape | |
14 | characters when needed, replace the old separator with the new one. | |
15 | Also fixes that recalling a "/" search for a "?" command messes up | |
16 | trailing flags. | |
17 | Files: src/eval.c, src/ex_getln.c, src/normal.c, src/proto/ex_getln.pro, | |
18 | src/search.c, src/tag.c | |
19 | ||
20 | ||
21 | *** ../vim-6.2.192/src/eval.c Sun Jan 18 20:46:13 2004 | |
22 | --- src/eval.c Sun Jan 18 16:51:58 2004 | |
23 | *************** | |
24 | *** 5140,5146 **** | |
25 | str = get_var_string_buf(&argvars[1], buf); | |
26 | if (*str != NUL) | |
27 | { | |
28 | ! add_to_history(histype, str, FALSE); | |
29 | retvar->var_val.var_number = TRUE; | |
30 | return; | |
31 | } | |
32 | --- 5140,5146 ---- | |
33 | str = get_var_string_buf(&argvars[1], buf); | |
34 | if (*str != NUL) | |
35 | { | |
36 | ! add_to_history(histype, str, FALSE, NUL); | |
37 | retvar->var_val.var_number = TRUE; | |
38 | return; | |
39 | } | |
40 | *** ../vim-6.2.192/src/ex_getln.c Sat Sep 27 19:36:46 2003 | |
41 | --- src/ex_getln.c Sun Jan 18 14:43:53 2004 | |
42 | *************** | |
43 | *** 42,48 **** | |
44 | typedef struct hist_entry | |
45 | { | |
46 | int hisnum; /* identifying number */ | |
47 | ! char_u *hisstr; /* actual entry */ | |
48 | } histentry_T; | |
49 | ||
50 | static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
51 | --- 42,48 ---- | |
52 | typedef struct hist_entry | |
53 | { | |
54 | int hisnum; /* identifying number */ | |
55 | ! char_u *hisstr; /* actual entry, separator char after the NUL */ | |
56 | } histentry_T; | |
57 | ||
58 | static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL}; | |
59 | *************** | |
60 | *** 1286,1291 **** | |
61 | --- 1286,1293 ---- | |
62 | if (hiscnt != i) /* jumped to other entry */ | |
63 | { | |
64 | char_u *p; | |
65 | + int len; | |
66 | + int old_firstc; | |
67 | ||
68 | vim_free(ccline.cmdbuff); | |
69 | if (hiscnt == hislen) | |
70 | *************** | |
71 | *** 1293,1302 **** | |
72 | else | |
73 | p = history[histype][hiscnt].hisstr; | |
74 | ||
75 | ! alloc_cmdbuff((int)STRLEN(p)); | |
76 | ! if (ccline.cmdbuff == NULL) | |
77 | ! goto returncmd; | |
78 | ! STRCPY(ccline.cmdbuff, p); | |
79 | ||
80 | ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
81 | redrawcmd(); | |
82 | --- 1295,1353 ---- | |
83 | else | |
84 | p = history[histype][hiscnt].hisstr; | |
85 | ||
86 | ! if (histype == HIST_SEARCH | |
87 | ! && p != lookfor | |
88 | ! && (old_firstc = p[STRLEN(p) + 1]) != firstc) | |
89 | ! { | |
90 | ! /* Correct for the separator character used when | |
91 | ! * adding the history entry vs the one used now. | |
92 | ! * First loop: count length. | |
93 | ! * Second loop: copy the characters. */ | |
94 | ! for (i = 0; i <= 1; ++i) | |
95 | ! { | |
96 | ! len = 0; | |
97 | ! for (j = 0; p[j] != NUL; ++j) | |
98 | ! { | |
99 | ! /* Replace old sep with new sep, unless it is | |
100 | ! * escaped. */ | |
101 | ! if (p[j] == old_firstc | |
102 | ! && (j == 0 || p[j - 1] != '\\')) | |
103 | ! { | |
104 | ! if (i > 0) | |
105 | ! ccline.cmdbuff[len] = firstc; | |
106 | ! } | |
107 | ! else | |
108 | ! { | |
109 | ! /* Escape new sep, unless it is already | |
110 | ! * escaped. */ | |
111 | ! if (p[j] == firstc | |
112 | ! && (j == 0 || p[j - 1] != '\\')) | |
113 | ! { | |
114 | ! if (i > 0) | |
115 | ! ccline.cmdbuff[len] = '\\'; | |
116 | ! ++len; | |
117 | ! } | |
118 | ! if (i > 0) | |
119 | ! ccline.cmdbuff[len] = p[j]; | |
120 | ! } | |
121 | ! ++len; | |
122 | ! } | |
123 | ! if (i == 0) | |
124 | ! { | |
125 | ! alloc_cmdbuff(len); | |
126 | ! if (ccline.cmdbuff == NULL) | |
127 | ! goto returncmd; | |
128 | ! } | |
129 | ! } | |
130 | ! ccline.cmdbuff[len] = NUL; | |
131 | ! } | |
132 | ! else | |
133 | ! { | |
134 | ! alloc_cmdbuff((int)STRLEN(p)); | |
135 | ! if (ccline.cmdbuff == NULL) | |
136 | ! goto returncmd; | |
137 | ! STRCPY(ccline.cmdbuff, p); | |
138 | ! } | |
139 | ||
140 | ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff); | |
141 | redrawcmd(); | |
142 | *************** | |
143 | *** 1556,1562 **** | |
144 | if (ccline.cmdlen && firstc != NUL | |
145 | && (some_key_typed || histype == HIST_SEARCH)) | |
146 | { | |
147 | ! add_to_history(histype, ccline.cmdbuff, TRUE); | |
148 | if (firstc == ':') | |
149 | { | |
150 | vim_free(new_last_cmdline); | |
151 | --- 1607,1614 ---- | |
152 | if (ccline.cmdlen && firstc != NUL | |
153 | && (some_key_typed || histype == HIST_SEARCH)) | |
154 | { | |
155 | ! add_to_history(histype, ccline.cmdbuff, TRUE, | |
156 | ! histype == HIST_SEARCH ? firstc : NUL); | |
157 | if (firstc == ':') | |
158 | { | |
159 | vim_free(new_last_cmdline); | |
160 | *************** | |
161 | *** 4185,4196 **** | |
162 | * values. | |
163 | */ | |
164 | void | |
165 | ! add_to_history(histype, new_entry, in_map) | |
166 | int histype; | |
167 | char_u *new_entry; | |
168 | int in_map; /* consider maptick when inside a mapping */ | |
169 | { | |
170 | histentry_T *hisptr; | |
171 | ||
172 | if (hislen == 0) /* no history */ | |
173 | return; | |
174 | --- 4239,4252 ---- | |
175 | * values. | |
176 | */ | |
177 | void | |
178 | ! add_to_history(histype, new_entry, in_map, sep) | |
179 | int histype; | |
180 | char_u *new_entry; | |
181 | int in_map; /* consider maptick when inside a mapping */ | |
182 | + int sep; /* separator character used (search hist) */ | |
183 | { | |
184 | histentry_T *hisptr; | |
185 | + int len; | |
186 | ||
187 | if (hislen == 0) /* no history */ | |
188 | return; | |
189 | *************** | |
190 | *** 4221,4227 **** | |
191 | hisidx[histype] = 0; | |
192 | hisptr = &history[histype][hisidx[histype]]; | |
193 | vim_free(hisptr->hisstr); | |
194 | ! hisptr->hisstr = vim_strsave(new_entry); | |
195 | hisptr->hisnum = ++hisnum[histype]; | |
196 | if (histype == HIST_SEARCH && in_map) | |
197 | last_maptick = maptick; | |
198 | --- 4277,4289 ---- | |
199 | hisidx[histype] = 0; | |
200 | hisptr = &history[histype][hisidx[histype]]; | |
201 | vim_free(hisptr->hisstr); | |
202 | ! | |
203 | ! /* Store the separator after the NUL of the string. */ | |
204 | ! len = STRLEN(new_entry); | |
205 | ! hisptr->hisstr = vim_strnsave(new_entry, len + 2); | |
206 | ! if (hisptr->hisstr != NULL) | |
207 | ! hisptr->hisstr[len + 1] = sep; | |
208 | ! | |
209 | hisptr->hisnum = ++hisnum[histype]; | |
210 | if (histype == HIST_SEARCH && in_map) | |
211 | last_maptick = maptick; | |
212 | *************** | |
213 | *** 4586,4592 **** | |
214 | if (i == hislen) | |
215 | i = 0; | |
216 | if (hist[i].hisstr != NULL | |
217 | ! && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
218 | { | |
219 | msg_putchar('\n'); | |
220 | sprintf((char *)IObuff, "%c%6d %s", i == idx ? '>' : ' ', | |
221 | --- 4648,4654 ---- | |
222 | if (i == hislen) | |
223 | i = 0; | |
224 | if (hist[i].hisstr != NULL | |
225 | ! && hist[i].hisnum >= j && hist[i].hisnum <= k) | |
226 | { | |
227 | msg_putchar('\n'); | |
228 | sprintf((char *)IObuff, "%c%6d %s", i == idx ? '>' : ' ', | |
229 | *************** | |
230 | *** 4682,4697 **** | |
231 | vir_T *virp; | |
232 | { | |
233 | int type; | |
234 | char_u *val; | |
235 | ||
236 | type = hist_char2type(virp->vir_line[0]); | |
237 | if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
238 | { | |
239 | ! val = viminfo_readstring(virp, 1, TRUE); | |
240 | if (val != NULL) | |
241 | { | |
242 | if (!in_history(type, val, viminfo_add_at_front)) | |
243 | viminfo_history[type][viminfo_hisidx[type]++] = val; | |
244 | else | |
245 | vim_free(val); | |
246 | } | |
247 | --- 4744,4782 ---- | |
248 | vir_T *virp; | |
249 | { | |
250 | int type; | |
251 | + int sep; | |
252 | + int len; | |
253 | char_u *val; | |
254 | ||
255 | type = hist_char2type(virp->vir_line[0]); | |
256 | if (viminfo_hisidx[type] < viminfo_hislen[type]) | |
257 | { | |
258 | ! /* Use a zero offset, so that we have some extra space in the | |
259 | ! * allocated memory for the separator. */ | |
260 | ! val = viminfo_readstring(virp, 0, TRUE); | |
261 | if (val != NULL) | |
262 | { | |
263 | if (!in_history(type, val, viminfo_add_at_front)) | |
264 | + { | |
265 | + len = STRLEN(val); | |
266 | + if (type == HIST_SEARCH) | |
267 | + { | |
268 | + /* Search entry: Move the separator from the second column | |
269 | + * to after the NUL. */ | |
270 | + sep = val[1]; | |
271 | + --len; | |
272 | + mch_memmove(val, val + 2, (size_t)len); | |
273 | + val[len + 1] = (sep == ' ' ? NUL : sep); | |
274 | + } | |
275 | + else | |
276 | + { | |
277 | + /* Not a search entry: No separator in the viminfo file, | |
278 | + * add a NUL separator. */ | |
279 | + mch_memmove(val, val + 1, (size_t)len); | |
280 | + val[len + 1] = NUL; | |
281 | + } | |
282 | viminfo_history[type][viminfo_hisidx[type]++] = val; | |
283 | + } | |
284 | else | |
285 | vim_free(val); | |
286 | } | |
287 | *************** | |
288 | *** 4757,4762 **** | |
289 | --- 4842,4849 ---- | |
290 | int i; | |
291 | int type; | |
292 | int num_saved; | |
293 | + char_u *p; | |
294 | + int c; | |
295 | ||
296 | init_history(); | |
297 | if (hislen == 0) | |
298 | *************** | |
299 | *** 4779,4788 **** | |
300 | if (i >= 0) | |
301 | while (num_saved--) | |
302 | { | |
303 | ! if (history[type][i].hisstr != NULL) | |
304 | { | |
305 | putc(hist_type2char(type, TRUE), fp); | |
306 | ! viminfo_writestring(fp, history[type][i].hisstr); | |
307 | } | |
308 | if (--i < 0) | |
309 | i = hislen - 1; | |
310 | --- 4866,4883 ---- | |
311 | if (i >= 0) | |
312 | while (num_saved--) | |
313 | { | |
314 | ! p = history[type][i].hisstr; | |
315 | ! if (p != NULL) | |
316 | { | |
317 | putc(hist_type2char(type, TRUE), fp); | |
318 | ! /* For the search history: put the separator in the second | |
319 | ! * column; use a space if there isn't one. */ | |
320 | ! if (type == HIST_SEARCH) | |
321 | ! { | |
322 | ! c = p[STRLEN(p) + 1]; | |
323 | ! putc(c == NUL ? ' ' : c, fp); | |
324 | ! } | |
325 | ! viminfo_writestring(fp, p); | |
326 | } | |
327 | if (--i < 0) | |
328 | i = hislen - 1; | |
329 | *** ../vim-6.2.192/src/normal.c Sun Jan 18 20:28:26 2004 | |
330 | --- src/normal.c Sun Jan 18 18:49:04 2004 | |
331 | *************** | |
332 | *** 4920,4926 **** | |
333 | STRCAT(buf, "\\>"); | |
334 | #ifdef FEAT_CMDHIST | |
335 | /* put pattern in search history */ | |
336 | ! add_to_history(HIST_SEARCH, buf, TRUE); | |
337 | #endif | |
338 | normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); | |
339 | } | |
340 | --- 4932,4938 ---- | |
341 | STRCAT(buf, "\\>"); | |
342 | #ifdef FEAT_CMDHIST | |
343 | /* put pattern in search history */ | |
344 | ! add_to_history(HIST_SEARCH, buf, TRUE, NUL); | |
345 | #endif | |
346 | normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0); | |
347 | } | |
348 | *** ../vim-6.2.192/src/proto/ex_getln.pro Sun Aug 10 22:24:37 2003 | |
349 | --- src/proto/ex_getln.pro Sun Jan 18 13:36:26 2004 | |
350 | *************** | |
351 | *** 25,31 **** | |
352 | int ExpandGeneric __ARGS((expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file, char_u *((*func)(expand_T *, int)))); | |
353 | char_u *globpath __ARGS((char_u *path, char_u *file)); | |
354 | int get_histtype __ARGS((char_u *name)); | |
355 | ! void add_to_history __ARGS((int histype, char_u *new_entry, int in_map)); | |
356 | int get_history_idx __ARGS((int histype)); | |
357 | char_u *get_history_entry __ARGS((int histype, int idx)); | |
358 | int clr_history __ARGS((int histype)); | |
359 | --- 25,31 ---- | |
360 | int ExpandGeneric __ARGS((expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file, char_u *((*func)(expand_T *, int)))); | |
361 | char_u *globpath __ARGS((char_u *path, char_u *file)); | |
362 | int get_histtype __ARGS((char_u *name)); | |
363 | ! void add_to_history __ARGS((int histype, char_u *new_entry, int in_map, int sep)); | |
364 | int get_history_idx __ARGS((int histype)); | |
365 | char_u *get_history_entry __ARGS((int histype, int idx)); | |
366 | int clr_history __ARGS((int histype)); | |
367 | *** ../vim-6.2.192/src/search.c Sat Sep 27 19:36:47 2003 | |
368 | --- src/search.c Sun Jan 18 13:05:15 2004 | |
369 | *************** | |
370 | *** 172,178 **** | |
371 | } | |
372 | #ifdef FEAT_CMDHIST | |
373 | else if (options & SEARCH_HIS) /* put new pattern in history */ | |
374 | ! add_to_history(HIST_SEARCH, pat, TRUE); | |
375 | #endif | |
376 | ||
377 | #ifdef FEAT_RIGHTLEFT | |
378 | --- 172,178 ---- | |
379 | } | |
380 | #ifdef FEAT_CMDHIST | |
381 | else if (options & SEARCH_HIS) /* put new pattern in history */ | |
382 | ! add_to_history(HIST_SEARCH, pat, TRUE, NUL); | |
383 | #endif | |
384 | ||
385 | #ifdef FEAT_RIGHTLEFT | |
386 | *** ../vim-6.2.192/src/tag.c Sun Jan 18 20:58:01 2004 | |
387 | --- src/tag.c Sun Jan 18 13:05:42 2004 | |
388 | *************** | |
389 | *** 2699,2705 **** | |
390 | #if 0 /* disabled for now */ | |
391 | #ifdef FEAT_CMDHIST | |
392 | /* put pattern in search history */ | |
393 | ! add_to_history(HIST_SEARCH, pbuf + 1, TRUE); | |
394 | #endif | |
395 | #endif | |
396 | save_lnum = curwin->w_cursor.lnum; | |
397 | --- 2699,2705 ---- | |
398 | #if 0 /* disabled for now */ | |
399 | #ifdef FEAT_CMDHIST | |
400 | /* put pattern in search history */ | |
401 | ! add_to_history(HIST_SEARCH, pbuf + 1, TRUE, pbuf[0]); | |
402 | #endif | |
403 | #endif | |
404 | save_lnum = curwin->w_cursor.lnum; | |
405 | *** ../vim-6.2.192/src/version.c Sun Jan 18 21:22:26 2004 | |
406 | --- src/version.c Sun Jan 18 21:24:10 2004 | |
407 | *************** | |
408 | *** 639,640 **** | |
409 | --- 639,642 ---- | |
410 | { /* Add new patch number below this line */ | |
411 | + /**/ | |
412 | + 193, | |
413 | /**/ | |
414 | ||
415 | -- | |
416 | WOMAN: Dennis, there's some lovely filth down here. Oh -- how d'you do? | |
417 | ARTHUR: How do you do, good lady. I am Arthur, King of the Britons. | |
418 | Who's castle is that? | |
419 | WOMAN: King of the who? | |
420 | The Quest for the Holy Grail (Monty Python) | |
421 | ||
422 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
423 | /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
424 | \\\ Project leader for A-A-P -- http://www.A-A-P.org /// | |
425 | \\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html /// |