4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
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
17 Files: src/eval.c, src/ex_getln.c, src/normal.c, src/proto/ex_getln.pro,
18 src/search.c, src/tag.c
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
25 str = get_var_string_buf(&argvars[1], buf);
28 ! add_to_history(histype, str, FALSE);
29 retvar->var_val.var_number = TRUE;
33 str = get_var_string_buf(&argvars[1], buf);
36 ! add_to_history(histype, str, FALSE, NUL);
37 retvar->var_val.var_number = TRUE;
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
44 typedef struct hist_entry
46 int hisnum; /* identifying number */
47 ! char_u *hisstr; /* actual entry */
50 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL};
52 typedef struct hist_entry
54 int hisnum; /* identifying number */
55 ! char_u *hisstr; /* actual entry, separator char after the NUL */
58 static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL};
62 if (hiscnt != i) /* jumped to other entry */
68 vim_free(ccline.cmdbuff);
73 p = history[histype][hiscnt].hisstr;
75 ! alloc_cmdbuff((int)STRLEN(p));
76 ! if (ccline.cmdbuff == NULL)
78 ! STRCPY(ccline.cmdbuff, p);
80 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff);
84 p = history[histype][hiscnt].hisstr;
86 ! if (histype == HIST_SEARCH
88 ! && (old_firstc = p[STRLEN(p) + 1]) != firstc)
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)
97 ! for (j = 0; p[j] != NUL; ++j)
99 ! /* Replace old sep with new sep, unless it is
101 ! if (p[j] == old_firstc
102 ! && (j == 0 || p[j - 1] != '\\'))
105 ! ccline.cmdbuff[len] = firstc;
109 ! /* Escape new sep, unless it is already
112 ! && (j == 0 || p[j - 1] != '\\'))
115 ! ccline.cmdbuff[len] = '\\';
119 ! ccline.cmdbuff[len] = p[j];
125 ! alloc_cmdbuff(len);
126 ! if (ccline.cmdbuff == NULL)
130 ! ccline.cmdbuff[len] = NUL;
134 ! alloc_cmdbuff((int)STRLEN(p));
135 ! if (ccline.cmdbuff == NULL)
137 ! STRCPY(ccline.cmdbuff, p);
140 ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff);
144 if (ccline.cmdlen && firstc != NUL
145 && (some_key_typed || histype == HIST_SEARCH))
147 ! add_to_history(histype, ccline.cmdbuff, TRUE);
150 vim_free(new_last_cmdline);
152 if (ccline.cmdlen && firstc != NUL
153 && (some_key_typed || histype == HIST_SEARCH))
155 ! add_to_history(histype, ccline.cmdbuff, TRUE,
156 ! histype == HIST_SEARCH ? firstc : NUL);
159 vim_free(new_last_cmdline);
165 ! add_to_history(histype, new_entry, in_map)
168 int in_map; /* consider maptick when inside a mapping */
172 if (hislen == 0) /* no history */
178 ! add_to_history(histype, new_entry, in_map, sep)
181 int in_map; /* consider maptick when inside a mapping */
182 + int sep; /* separator character used (search hist) */
187 if (hislen == 0) /* no history */
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;
200 hisptr = &history[histype][hisidx[histype]];
201 vim_free(hisptr->hisstr);
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;
209 hisptr->hisnum = ++hisnum[histype];
210 if (histype == HIST_SEARCH && in_map)
211 last_maptick = maptick;
216 if (hist[i].hisstr != NULL
217 ! && hist[i].hisnum >= j && hist[i].hisnum <= k)
220 sprintf((char *)IObuff, "%c%6d %s", i == idx ? '>' : ' ',
224 if (hist[i].hisstr != NULL
225 ! && hist[i].hisnum >= j && hist[i].hisnum <= k)
228 sprintf((char *)IObuff, "%c%6d %s", i == idx ? '>' : ' ',
236 type = hist_char2type(virp->vir_line[0]);
237 if (viminfo_hisidx[type] < viminfo_hislen[type])
239 ! val = viminfo_readstring(virp, 1, TRUE);
242 if (!in_history(type, val, viminfo_add_at_front))
243 viminfo_history[type][viminfo_hisidx[type]++] = val;
255 type = hist_char2type(virp->vir_line[0]);
256 if (viminfo_hisidx[type] < viminfo_hislen[type])
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);
263 if (!in_history(type, val, viminfo_add_at_front))
266 + if (type == HIST_SEARCH)
268 + /* Search entry: Move the separator from the second column
269 + * to after the NUL. */
272 + mch_memmove(val, val + 2, (size_t)len);
273 + val[len + 1] = (sep == ' ' ? NUL : sep);
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;
282 viminfo_history[type][viminfo_hisidx[type]++] = val;
303 ! if (history[type][i].hisstr != NULL)
305 putc(hist_type2char(type, TRUE), fp);
306 ! viminfo_writestring(fp, history[type][i].hisstr);
314 ! p = history[type][i].hisstr;
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)
322 ! c = p[STRLEN(p) + 1];
323 ! putc(c == NUL ? ' ' : c, fp);
325 ! viminfo_writestring(fp, p);
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
335 /* put pattern in search history */
336 ! add_to_history(HIST_SEARCH, buf, TRUE);
338 normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0);
343 /* put pattern in search history */
344 ! add_to_history(HIST_SEARCH, buf, TRUE, NUL);
346 normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0);
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
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));
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
373 else if (options & SEARCH_HIS) /* put new pattern in history */
374 ! add_to_history(HIST_SEARCH, pat, TRUE);
377 #ifdef FEAT_RIGHTLEFT
381 else if (options & SEARCH_HIS) /* put new pattern in history */
382 ! add_to_history(HIST_SEARCH, pat, TRUE, NUL);
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
390 #if 0 /* disabled for now */
392 /* put pattern in search history */
393 ! add_to_history(HIST_SEARCH, pbuf + 1, TRUE);
396 save_lnum = curwin->w_cursor.lnum;
398 #if 0 /* disabled for now */
400 /* put pattern in search history */
401 ! add_to_history(HIST_SEARCH, pbuf + 1, TRUE, pbuf[0]);
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
410 { /* Add new patch number below this line */
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)
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 ///