4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: When using custom completion end up with no matches.
12 Solution: Make cmd_numfiles and cmd_files local to completion to avoid that
13 they are overwritten when ExpandOne() is called recursively by
15 Files: src/eval.c, src/ex_docmd.c, src/ex_getln.c, src/proto/ex_getln.pro,
16 src/misc1.c, src/structs.h, src/tag.c
19 *** ../vim-6.2.062/src/eval.c Sun Jul 27 15:01:56 2003
20 --- src/eval.c Thu Jul 31 19:47:34 2003
23 * for 'suffixes' and 'wildignore' */
24 if (argvars[1].var_type != VAR_UNKNOWN && get_var_number(&argvars[1]))
25 flags |= WILD_KEEP_ALL;
26 xpc.xp_context = EXPAND_FILES;
27 - xpc.xp_backslash = XP_BS_NONE;
28 retvar->var_val.var_string = ExpandOne(&xpc, s, NULL, flags, WILD_ALL);
33 * for 'suffixes' and 'wildignore' */
34 if (argvars[1].var_type != VAR_UNKNOWN && get_var_number(&argvars[1]))
35 flags |= WILD_KEEP_ALL;
37 xpc.xp_context = EXPAND_FILES;
38 retvar->var_val.var_string = ExpandOne(&xpc, s, NULL, flags, WILD_ALL);
39 + ExpandCleanup(&xpc);
48 xpc.xp_context = EXPAND_FILES;
49 - xpc.xp_backslash = XP_BS_NONE;
50 retvar->var_type = VAR_STRING;
51 retvar->var_val.var_string = ExpandOne(&xpc, get_var_string(&argvars[0]),
52 NULL, WILD_USE_NL|WILD_SILENT, WILD_ALL);
61 xpc.xp_context = EXPAND_FILES;
62 retvar->var_type = VAR_STRING;
63 retvar->var_val.var_string = ExpandOne(&xpc, get_var_string(&argvars[0]),
64 NULL, WILD_USE_NL|WILD_SILENT, WILD_ALL);
65 + ExpandCleanup(&xpc);
69 *** ../vim-6.2.062/src/ex_docmd.c Sun Jul 27 14:35:27 2003
70 --- src/ex_docmd.c Sat Jul 26 18:36:31 2003
76 xpc.xp_context = EXPAND_FILES;
77 ! xpc.xp_backslash = XP_BS_NONE;
78 ! if ((p = ExpandOne(&xpc, eap->arg, NULL,
79 WILD_LIST_NOTFOUND|WILD_ADD_SLASH,
80 ! WILD_EXPAND_FREE)) == NULL)
89 xpc.xp_context = EXPAND_FILES;
90 ! p = ExpandOne(&xpc, eap->arg, NULL,
91 WILD_LIST_NOTFOUND|WILD_ADD_SLASH,
93 ! ExpandCleanup(&xpc);
98 *** ../vim-6.2.062/src/ex_getln.c Thu May 29 22:45:46 2003
99 --- src/ex_getln.c Sat Jul 26 18:57:18 2003
103 static struct cmdline_info ccline; /* current cmdline_info */
105 - static int cmd_numfiles = -1; /* number of files found by
106 - file name completion */
107 - static char_u **cmd_files = NULL; /* list of files */
108 static int cmd_showtail; /* Only show path tail in lists ? */
115 ccline.cmdlen = ccline.cmdpos = 0;
116 ccline.cmdbuff[0] = NUL;
120 #ifdef FEAT_RIGHTLEFT
121 if (curwin->w_p_rl && *curwin->w_p_rlc == 's'
122 && (firstc == '/' || firstc == '?'))
125 && c != K_PAGEDOWN && c != K_PAGEUP
126 && c != K_KPAGEDOWN && c != K_KPAGEUP
127 && c != K_LEFT && c != K_RIGHT
128 ! && (cmd_numfiles > 0 || (c != Ctrl_P && c != Ctrl_N)))
133 && c != K_PAGEDOWN && c != K_PAGEUP
134 && c != K_KPAGEDOWN && c != K_KPAGEUP
135 && c != K_LEFT && c != K_RIGHT
136 ! && (xpc.xp_numfiles > 0 || (c != Ctrl_P && c != Ctrl_N)))
143 * <S-Tab> works like CTRL-P (unless 'wc' is <S-Tab>).
145 ! if (c != p_wc && c == K_S_TAB && cmd_numfiles != -1)
151 * <S-Tab> works like CTRL-P (unless 'wc' is <S-Tab>).
153 ! if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles != -1)
161 /* free expanded names when finished walking through matches */
162 ! if (cmd_numfiles != -1
163 && !(c == p_wc && KeyTyped) && c != p_wcm
164 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A
169 /* free expanded names when finished walking through matches */
170 ! if (xpc.xp_numfiles != -1
171 && !(c == p_wc && KeyTyped) && c != p_wcm
172 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A
177 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm)
179 ! if (cmd_numfiles > 0) /* typed p_wc at least twice */
181 /* if 'wildmode' contains "list" may still need to list */
182 ! if (cmd_numfiles > 1
184 && (wim_flags[wim_index] & WIM_LIST))
188 if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm)
190 ! if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */
192 /* if 'wildmode' contains "list" may still need to list */
193 ! if (xpc.xp_numfiles > 1
195 && (wim_flags[wim_index] & WIM_LIST))
199 /* when more than one match, and 'wildmode' first contains
200 * "list", or no change and 'wildmode' contains "longest,list",
201 * list all matches */
202 ! if (res == OK && cmd_numfiles > 1)
204 /* a "longest" that didn't do anything is skipped (but not
207 /* when more than one match, and 'wildmode' first contains
208 * "list", or no change and 'wildmode' contains "longest,list",
209 * list all matches */
210 ! if (res == OK && xpc.xp_numfiles > 1)
212 /* a "longest" that didn't do anything is skipped (but not
219 ! else if (cmd_numfiles == -1)
220 xpc.xp_context = EXPAND_NOTHING;
227 ! else if (xpc.xp_numfiles == -1)
228 xpc.xp_context = EXPAND_NOTHING;
234 case Ctrl_N: /* next match */
235 case Ctrl_P: /* previous match */
236 ! if (cmd_numfiles > 0)
238 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, 0)
242 case Ctrl_N: /* next match */
243 case Ctrl_P: /* previous match */
244 ! if (xpc.xp_numfiles > 0)
246 if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, 0)
254 + ExpandCleanup(&xpc);
256 #ifdef FEAT_SEARCH_EXTRA
264 ! if (cmd_numfiles == -1)
266 set_expand_context(xp);
267 cmd_showtail = !glob_in_path_prefix(xp);
272 ! if (xp->xp_numfiles == -1)
274 set_expand_context(xp);
275 cmd_showtail = !glob_in_path_prefix(xp);
278 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL)
281 ! if (cmd_numfiles <= 0 && p2 == NULL)
283 ! else if (cmd_numfiles == 1)
284 /* free expanded pattern */
285 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE);
288 if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL)
291 ! if (xp->xp_numfiles <= 0 && p2 == NULL)
293 ! else if (xp->xp_numfiles == 1)
294 /* free expanded pattern */
295 (void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE);
299 * Return a pointer to alloced memory containing the new string.
300 * Return NULL for failure.
302 ! * Results are cached in cmd_files and cmd_numfiles.
304 * mode = WILD_FREE: just free previously expanded matches
305 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches
307 * Return a pointer to alloced memory containing the new string.
308 * Return NULL for failure.
310 ! * Results are cached in xp->xp_files and xp->xp_numfiles.
312 * mode = WILD_FREE: just free previously expanded matches
313 * mode = WILD_EXPAND_FREE: normal expansion, do not keep matches
317 if (mode == WILD_NEXT || mode == WILD_PREV)
319 ! if (cmd_numfiles > 0)
321 if (mode == WILD_PREV)
324 ! findex = cmd_numfiles;
327 else /* mode == WILD_NEXT */
330 if (mode == WILD_NEXT || mode == WILD_PREV)
332 ! if (xp->xp_numfiles > 0)
334 if (mode == WILD_PREV)
337 ! findex = xp->xp_numfiles;
340 else /* mode == WILD_NEXT */
345 if (orig_save == NULL)
346 ! findex = cmd_numfiles - 1;
350 ! if (findex >= cmd_numfiles)
352 if (orig_save == NULL)
357 if (orig_save == NULL)
358 ! findex = xp->xp_numfiles - 1;
362 ! if (findex >= xp->xp_numfiles)
364 if (orig_save == NULL)
371 ! win_redr_status_matches(xp, cmd_numfiles, cmd_files, findex,
375 return vim_strsave(orig_save);
376 ! return vim_strsave(cmd_files[findex]);
383 ! if (cmd_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST)
385 ! FreeWild(cmd_numfiles, cmd_files);
394 ! win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files,
395 ! findex, cmd_showtail);
398 return vim_strsave(orig_save);
399 ! return vim_strsave(xp->xp_files[findex]);
406 ! if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST)
408 ! FreeWild(xp->xp_numfiles, xp->xp_files);
409 ! xp->xp_numfiles = -1;
415 if (mode == WILD_FREE) /* only release file name */
418 ! if (cmd_numfiles == -1)
423 if (mode == WILD_FREE) /* only release file name */
426 ! if (xp->xp_numfiles == -1)
435 ! if (ExpandFromContext(xp, str, &cmd_numfiles, &cmd_files,
443 ! if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files,
449 EMSG2(_(e_nomatch2), str);
452 ! else if (cmd_numfiles == 0)
454 if (!(options & WILD_SILENT))
455 EMSG2(_(e_nomatch2), str);
457 EMSG2(_(e_nomatch2), str);
460 ! else if (xp->xp_numfiles == 0)
462 if (!(options & WILD_SILENT))
463 EMSG2(_(e_nomatch2), str);
468 /* Escape the matches for use on the command line. */
469 ! ExpandEscape(xp, str, cmd_numfiles, cmd_files, options);
472 * Check for matching suffixes in file names.
474 if (mode != WILD_ALL && mode != WILD_LONGEST)
477 ! non_suf_match = cmd_numfiles;
480 if ((xp->xp_context == EXPAND_FILES
481 || xp->xp_context == EXPAND_DIRECTORIES)
482 ! && cmd_numfiles > 1)
485 * More than one match; check suffix.
489 /* Escape the matches for use on the command line. */
490 ! ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options);
493 * Check for matching suffixes in file names.
495 if (mode != WILD_ALL && mode != WILD_LONGEST)
497 ! if (xp->xp_numfiles)
498 ! non_suf_match = xp->xp_numfiles;
501 if ((xp->xp_context == EXPAND_FILES
502 || xp->xp_context == EXPAND_DIRECTORIES)
503 ! && xp->xp_numfiles > 1)
506 * More than one match; check suffix.
511 for (i = 0; i < 2; ++i)
512 ! if (match_suffix(cmd_files[i]))
515 if (non_suf_match != 1)
519 for (i = 0; i < 2; ++i)
520 ! if (match_suffix(xp->xp_files[i]))
523 if (non_suf_match != 1)
528 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE))
529 ! ss = vim_strsave(cmd_files[0]);
534 /* Find longest common part */
535 ! if (mode == WILD_LONGEST && cmd_numfiles > 0)
537 ! for (len = 0; cmd_files[0][len]; ++len)
539 ! for (i = 0; i < cmd_numfiles; ++i)
541 #ifdef CASE_INSENSITIVE_FILENAME
542 if (xp->xp_context == EXPAND_DIRECTORIES
543 || xp->xp_context == EXPAND_FILES
544 || xp->xp_context == EXPAND_BUFFERS)
546 ! if (TOLOWER_LOC(cmd_files[i][len]) !=
547 ! TOLOWER_LOC(cmd_files[0][len]))
552 ! if (cmd_files[i][len] != cmd_files[0][len])
555 ! if (i < cmd_numfiles)
557 if (!(options & WILD_NO_BEEP))
562 if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE))
563 ! ss = vim_strsave(xp->xp_files[0]);
568 /* Find longest common part */
569 ! if (mode == WILD_LONGEST && xp->xp_numfiles > 0)
571 ! for (len = 0; xp->xp_files[0][len]; ++len)
573 ! for (i = 0; i < xp->xp_numfiles; ++i)
575 #ifdef CASE_INSENSITIVE_FILENAME
576 if (xp->xp_context == EXPAND_DIRECTORIES
577 || xp->xp_context == EXPAND_FILES
578 || xp->xp_context == EXPAND_BUFFERS)
580 ! if (TOLOWER_LOC(xp->xp_files[i][len]) !=
581 ! TOLOWER_LOC(xp->xp_files[0][len]))
586 ! if (xp->xp_files[i][len] != xp->xp_files[0][len])
589 ! if (i < xp->xp_numfiles)
591 if (!(options & WILD_NO_BEEP))
595 ss = alloc((unsigned)len + 1);
598 ! STRNCPY(ss, cmd_files[0], len);
601 findex = -1; /* next p_wc gets first one */
604 /* Concatenate all matching names */
605 ! if (mode == WILD_ALL && cmd_numfiles > 0)
608 ! for (i = 0; i < cmd_numfiles; ++i)
609 ! len += (long_u)STRLEN(cmd_files[i]) + 1;
610 ss = lalloc(len, TRUE);
614 ! for (i = 0; i < cmd_numfiles; ++i)
616 ! STRCAT(ss, cmd_files[i]);
617 ! if (i != cmd_numfiles - 1)
618 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " ");
623 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL)
625 ! FreeWild(cmd_numfiles, cmd_files);
633 ExpandEscape(xp, str, numfiles, files, options)
636 ss = alloc((unsigned)len + 1);
639 ! STRNCPY(ss, xp->xp_files[0], len);
642 findex = -1; /* next p_wc gets first one */
645 /* Concatenate all matching names */
646 ! if (mode == WILD_ALL && xp->xp_numfiles > 0)
649 ! for (i = 0; i < xp->xp_numfiles; ++i)
650 ! len += (long_u)STRLEN(xp->xp_files[i]) + 1;
651 ss = lalloc(len, TRUE);
655 ! for (i = 0; i < xp->xp_numfiles; ++i)
657 ! STRCAT(ss, xp->xp_files[i]);
658 ! if (i != xp->xp_numfiles - 1)
659 STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " ");
664 if (mode == WILD_EXPAND_FREE || mode == WILD_ALL)
671 + * Prepare an expand structure for use.
677 + xp->xp_backslash = XP_BS_NONE;
678 + xp->xp_numfiles = -1;
679 + xp->xp_files = NULL;
683 + * Cleanup an expand structure after use.
689 + if (xp->xp_numfiles >= 0)
691 + FreeWild(xp->xp_numfiles, xp->xp_files);
692 + xp->xp_numfiles = -1;
697 ExpandEscape(xp, str, numfiles, files, options)
704 ! if (cmd_numfiles == -1)
706 set_expand_context(xp);
707 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos,
712 ! if (xp->xp_numfiles == -1)
714 set_expand_context(xp);
715 i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos,
721 ! num_files = cmd_numfiles;
722 ! files_found = cmd_files;
723 showtail = cmd_showtail;
730 ! num_files = xp->xp_numfiles;
731 ! files_found = xp->xp_files;
732 showtail = cmd_showtail;
737 cmdline_row = msg_row; /* will put it back later */
740 ! if (cmd_numfiles == -1)
741 FreeWild(num_files, files_found);
745 cmdline_row = msg_row; /* will put it back later */
748 ! if (xp->xp_numfiles == -1)
749 FreeWild(num_files, files_found);
752 *** ../vim-6.2.062/src/proto/ex_getln.pro Sun Jun 1 12:26:09 2003
753 --- src/proto/ex_getln.pro Sat Jul 26 18:38:51 2003
757 void compute_cmdrow __ARGS((void));
758 void gotocmdline __ARGS((int clr));
759 char_u *ExpandOne __ARGS((expand_T *xp, char_u *str, char_u *orig, int options, int mode));
760 + void ExpandInit __ARGS((expand_T *xp));
761 + void ExpandCleanup __ARGS((expand_T *xp));
762 void ExpandEscape __ARGS((expand_T *xp, char_u *str, int numfiles, char_u **files, int options));
763 void tilde_replace __ARGS((char_u *orig_pat, int num_files, char_u **files));
764 char_u *sm_gettail __ARGS((char_u *s));
765 *** ../vim-6.2.062/src/misc1.c Thu May 29 20:32:05 2003
766 --- src/misc1.c Sat Jul 26 18:37:24 2003
772 xpc.xp_context = EXPAND_FILES;
773 - xpc.xp_backslash = XP_BS_NONE;
774 var = ExpandOne(&xpc, dst, NULL,
775 WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE);
784 xpc.xp_context = EXPAND_FILES;
785 var = ExpandOne(&xpc, dst, NULL,
786 WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE);
787 + ExpandCleanup(&xpc);
791 *** ../vim-6.2.062/src/structs.h Mon May 26 21:08:40 2003
792 --- src/structs.h Sat Jul 26 18:30:51 2003
796 char_u *xp_pattern; /* start of item to expand */
797 char_u *xp_arg; /* generic expansion argument */
798 int xp_backslash; /* one of the XP_BS_ values */
799 + int xp_numfiles; /* number of files found by
800 + file name completion */
801 + char_u **xp_files; /* list of files */
804 /* values for xp_backslash */
805 *** ../vim-6.2.062/src/tag.c Sun Jun 1 14:41:25 2003
806 --- src/tag.c Thu Jul 31 18:27:34 2003
810 if (expand && mch_has_wildcard(fname))
812 xpc.xp_context = EXPAND_FILES;
813 - xpc.xp_backslash = XP_BS_NONE;
814 expanded_fname = ExpandOne(&xpc, (char_u *)fname, NULL,
815 WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE);
816 if (expanded_fname != NULL)
817 fname = expanded_fname;
821 if (expand && mch_has_wildcard(fname))
824 xpc.xp_context = EXPAND_FILES;
825 expanded_fname = ExpandOne(&xpc, (char_u *)fname, NULL,
826 WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE);
827 + ExpandCleanup(&xpc);
828 if (expanded_fname != NULL)
829 fname = expanded_fname;
831 *** ../vim-6.2.062/src/version.c Sun Aug 10 14:52:30 2003
832 --- src/version.c Sun Aug 10 22:14:52 2003
836 { /* Add new patch number below this line */
842 From "know your smileys":
845 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
846 /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
847 \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
848 \\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html ///