static char_u *
get_next_or_prev_match(
int mode,
- expand_T *xp,
- char_u *orig_save)
+ expand_T *xp)
{
int findex = xp->xp_selected;
int ht;
// When wrapping around, return the original string, set findex to -1.
if (findex < 0)
{
- if (orig_save == NULL)
+ if (xp->xp_orig == NULL)
findex = xp->xp_numfiles - 1;
else
findex = -1;
}
if (findex >= xp->xp_numfiles)
{
- if (orig_save == NULL)
+ if (xp->xp_orig == NULL)
findex = 0;
else
findex = -1;
xp->xp_selected = findex;
if (findex == -1)
- return vim_strsave(orig_save);
+ return vim_strsave(xp->xp_orig);
return vim_strsave(xp->xp_files[findex]);
}
* Return NULL for failure.
*
* "orig" is the originally expanded string, copied to allocated memory. It
- * should either be kept in orig_save or freed. When "mode" is WILD_NEXT or
- * WILD_PREV "orig" should be NULL.
+ * should either be kept in "xp->xp_orig" or freed. When "mode" is WILD_NEXT
+ * or WILD_PREV "orig" should be NULL.
*
* Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode"
* is WILD_EXPAND_FREE or WILD_ALL.
int mode)
{
char_u *ss = NULL;
- static char_u *orig_save = NULL; // kept value of orig
int orig_saved = FALSE;
int i;
long_u len;
// first handle the case of using an old match
if (mode == WILD_NEXT || mode == WILD_PREV
|| mode == WILD_PAGEUP || mode == WILD_PAGEDOWN)
- return get_next_or_prev_match(mode, xp, orig_save);
+ return get_next_or_prev_match(mode, xp);
if (mode == WILD_CANCEL)
- ss = vim_strsave(orig_save ? orig_save : (char_u *)"");
+ ss = vim_strsave(xp->xp_orig ? xp->xp_orig : (char_u *)"");
else if (mode == WILD_APPLY)
ss = vim_strsave(xp->xp_selected == -1
- ? (orig_save ? orig_save : (char_u *)"")
+ ? (xp->xp_orig ? xp->xp_orig : (char_u *)"")
: xp->xp_files[xp->xp_selected]);
// free old names
{
FreeWild(xp->xp_numfiles, xp->xp_files);
xp->xp_numfiles = -1;
- VIM_CLEAR(orig_save);
+ VIM_CLEAR(xp->xp_orig);
// The entries from xp_files may be used in the PUM, remove it.
if (compl_match_array != NULL)
if (xp->xp_numfiles == -1 && mode != WILD_APPLY && mode != WILD_CANCEL)
{
- vim_free(orig_save);
- orig_save = orig;
+ vim_free(xp->xp_orig);
+ xp->xp_orig = orig;
orig_saved = TRUE;
ss = ExpandOne_start(mode, xp, str, options);
if (mode == WILD_EXPAND_FREE || mode == WILD_ALL)
ExpandCleanup(xp);
- // Free "orig" if it wasn't stored in "orig_save".
+ // Free "orig" if it wasn't stored in "xp->xp_orig".
if (!orig_saved)
vim_free(orig);
FreeWild(xp->xp_numfiles, xp->xp_files);
xp->xp_numfiles = -1;
}
+ VIM_CLEAR(xp->xp_orig);
}
/*
delfunc Check_customlist_completion
endfunc
+func Test_custom_completion_with_glob()
+ func TestGlobComplete(A, L, P)
+ return split(glob('Xglob*'), "\n")
+ endfunc
+
+ command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
+ call writefile([], 'Xglob1', 'D')
+ call writefile([], 'Xglob2', 'D')
+
+ call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
+
+ delcommand TestGlobComplete
+ delfunc TestGlobComplete
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab