Skip to content

Commit

Permalink
patch 7.4.1492
Browse files Browse the repository at this point in the history
Problem:    No command line completion for ":packadd".
Solution:   Implement completion. (Hirohito Higashi)
  • Loading branch information
brammool committed Mar 5, 2016
1 parent 019b9c6 commit 35ca0e7
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ex_docmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4198,6 +4198,11 @@ set_one_cmd_context(
xp->xp_pattern = arg;
break;

case CMD_packadd:
xp->xp_context = EXPAND_PACKADD;
xp->xp_pattern = arg;
break;

#if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
&& (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE))
case CMD_language:
Expand Down Expand Up @@ -5846,6 +5851,7 @@ static struct
{EXPAND_SYNTIME, "syntime"},
#endif
{EXPAND_SETTINGS, "option"},
{EXPAND_PACKADD, "packadd"},
{EXPAND_SHELLCMD, "shellcmd"},
#if defined(FEAT_SIGNS)
{EXPAND_SIGN, "sign"},
Expand Down
56 changes: 56 additions & 0 deletions src/ex_getln.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ static int expand_showtail(expand_T *xp);
#ifdef FEAT_CMDL_COMPL
static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg);
static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirname[]);
static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file);
# ifdef FEAT_CMDHIST
static char_u *get_history_arg(expand_T *xp, int idx);
# endif
Expand Down Expand Up @@ -4231,6 +4232,7 @@ addstar(
|| context == EXPAND_COMPILER
|| context == EXPAND_OWNSYNTAX
|| context == EXPAND_FILETYPE
|| context == EXPAND_PACKADD
|| (context == EXPAND_TAGS && fname[0] == '/'))
retval = vim_strnsave(fname, len);
else
Expand Down Expand Up @@ -4647,6 +4649,8 @@ ExpandFromContext(
if (xp->xp_context == EXPAND_USER_LIST)
return ExpandUserList(xp, num_file, file);
# endif
if (xp->xp_context == EXPAND_PACKADD)
return ExpandPackAddDir(pat, num_file, file);

regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
if (regmatch.regprog == NULL)
Expand Down Expand Up @@ -5180,6 +5184,58 @@ ExpandRTDir(
return OK;
}

/*
* Expand loadplugin names:
* 'packpath'/pack/ * /opt/{pat}
*/
static int
ExpandPackAddDir(
char_u *pat,
int *num_file,
char_u ***file)
{
char_u *s;
char_u *e;
char_u *match;
garray_T ga;
int i;
int pat_len;

*num_file = 0;
*file = NULL;
pat_len = (int)STRLEN(pat);
ga_init2(&ga, (int)sizeof(char *), 10);

s = alloc((unsigned)(pat_len + 26));
if (s == NULL)
{
ga_clear_strings(&ga);
return FAIL;
}
sprintf((char *)s, "pack/*/opt/%s*", pat);
globpath(p_pp, s, &ga, 0);
vim_free(s);

for (i = 0; i < ga.ga_len; ++i)
{
match = ((char_u **)ga.ga_data)[i];
s = gettail(match);
e = s + STRLEN(s);
mch_memmove(match, s, e - s + 1);
}

if (ga.ga_len == 0)
return FAIL;

/* Sort and remove duplicates which can happen when specifying multiple
* directories in dirnames. */
remove_duplicates(&ga);

*file = ga.ga_data;
*num_file = ga.ga_len;
return OK;
}

#endif

#if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO)
Expand Down
21 changes: 21 additions & 0 deletions src/testdir/test_packadd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,24 @@ func Test_packadd_noload()
packadd! mytest
call assert_equal(new_rtp, &rtp)
endfunc

" Check command-line completion for 'packadd'
func Test_packadd_completion()
let optdir1 = &packpath . '/pack/mine/opt'
let optdir2 = &packpath . '/pack/candidate/opt'

call mkdir(optdir1 . '/pluginA', 'p')
call mkdir(optdir1 . '/pluginC', 'p')
call mkdir(optdir2 . '/pluginB', 'p')
call mkdir(optdir2 . '/pluginC', 'p')

let li = []
call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
call assert_equal("packadd pluginA", li[0])
call assert_equal("packadd pluginB", li[1])
call assert_equal("packadd pluginC", li[2])
call assert_equal("packadd ", li[3])
endfunc
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1492,
/**/
1491,
/**/
Expand Down
1 change: 1 addition & 0 deletions src/vim.h
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ extern char *(*dyn_libintl_textdomain)(const char *domainname);
#define EXPAND_USER 42
#define EXPAND_SYNTIME 43
#define EXPAND_USER_ADDR_TYPE 44
#define EXPAND_PACKADD 45

/* Values for exmode_active (0 is no exmode) */
#define EXMODE_NORMAL 1
Expand Down

0 comments on commit 35ca0e7

Please sign in to comment.