Skip to content

Commit 35ca0e7

Browse files
committed
patch 7.4.1492
Problem: No command line completion for ":packadd". Solution: Implement completion. (Hirohito Higashi)
1 parent 019b9c6 commit 35ca0e7

5 files changed

Lines changed: 86 additions & 0 deletions

File tree

src/ex_docmd.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4198,6 +4198,11 @@ set_one_cmd_context(
41984198
xp->xp_pattern = arg;
41994199
break;
42004200

4201+
case CMD_packadd:
4202+
xp->xp_context = EXPAND_PACKADD;
4203+
xp->xp_pattern = arg;
4204+
break;
4205+
42014206
#if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
42024207
&& (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE))
42034208
case CMD_language:
@@ -5846,6 +5851,7 @@ static struct
58465851
{EXPAND_SYNTIME, "syntime"},
58475852
#endif
58485853
{EXPAND_SETTINGS, "option"},
5854+
{EXPAND_PACKADD, "packadd"},
58495855
{EXPAND_SHELLCMD, "shellcmd"},
58505856
#if defined(FEAT_SIGNS)
58515857
{EXPAND_SIGN, "sign"},

src/ex_getln.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ static int expand_showtail(expand_T *xp);
112112
#ifdef FEAT_CMDL_COMPL
113113
static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg);
114114
static int ExpandRTDir(char_u *pat, int *num_file, char_u ***file, char *dirname[]);
115+
static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file);
115116
# ifdef FEAT_CMDHIST
116117
static char_u *get_history_arg(expand_T *xp, int idx);
117118
# endif
@@ -4231,6 +4232,7 @@ addstar(
42314232
|| context == EXPAND_COMPILER
42324233
|| context == EXPAND_OWNSYNTAX
42334234
|| context == EXPAND_FILETYPE
4235+
|| context == EXPAND_PACKADD
42344236
|| (context == EXPAND_TAGS && fname[0] == '/'))
42354237
retval = vim_strnsave(fname, len);
42364238
else
@@ -4647,6 +4649,8 @@ ExpandFromContext(
46474649
if (xp->xp_context == EXPAND_USER_LIST)
46484650
return ExpandUserList(xp, num_file, file);
46494651
# endif
4652+
if (xp->xp_context == EXPAND_PACKADD)
4653+
return ExpandPackAddDir(pat, num_file, file);
46504654

46514655
regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
46524656
if (regmatch.regprog == NULL)
@@ -5180,6 +5184,58 @@ ExpandRTDir(
51805184
return OK;
51815185
}
51825186

5187+
/*
5188+
* Expand loadplugin names:
5189+
* 'packpath'/pack/ * /opt/{pat}
5190+
*/
5191+
static int
5192+
ExpandPackAddDir(
5193+
char_u *pat,
5194+
int *num_file,
5195+
char_u ***file)
5196+
{
5197+
char_u *s;
5198+
char_u *e;
5199+
char_u *match;
5200+
garray_T ga;
5201+
int i;
5202+
int pat_len;
5203+
5204+
*num_file = 0;
5205+
*file = NULL;
5206+
pat_len = (int)STRLEN(pat);
5207+
ga_init2(&ga, (int)sizeof(char *), 10);
5208+
5209+
s = alloc((unsigned)(pat_len + 26));
5210+
if (s == NULL)
5211+
{
5212+
ga_clear_strings(&ga);
5213+
return FAIL;
5214+
}
5215+
sprintf((char *)s, "pack/*/opt/%s*", pat);
5216+
globpath(p_pp, s, &ga, 0);
5217+
vim_free(s);
5218+
5219+
for (i = 0; i < ga.ga_len; ++i)
5220+
{
5221+
match = ((char_u **)ga.ga_data)[i];
5222+
s = gettail(match);
5223+
e = s + STRLEN(s);
5224+
mch_memmove(match, s, e - s + 1);
5225+
}
5226+
5227+
if (ga.ga_len == 0)
5228+
return FAIL;
5229+
5230+
/* Sort and remove duplicates which can happen when specifying multiple
5231+
* directories in dirnames. */
5232+
remove_duplicates(&ga);
5233+
5234+
*file = ga.ga_data;
5235+
*num_file = ga.ga_len;
5236+
return OK;
5237+
}
5238+
51835239
#endif
51845240

51855241
#if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO)

src/testdir/test_packadd.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,24 @@ func Test_packadd_noload()
5555
packadd! mytest
5656
call assert_equal(new_rtp, &rtp)
5757
endfunc
58+
59+
" Check command-line completion for 'packadd'
60+
func Test_packadd_completion()
61+
let optdir1 = &packpath . '/pack/mine/opt'
62+
let optdir2 = &packpath . '/pack/candidate/opt'
63+
64+
call mkdir(optdir1 . '/pluginA', 'p')
65+
call mkdir(optdir1 . '/pluginC', 'p')
66+
call mkdir(optdir2 . '/pluginB', 'p')
67+
call mkdir(optdir2 . '/pluginC', 'p')
68+
69+
let li = []
70+
call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
71+
call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
72+
call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
73+
call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
74+
call assert_equal("packadd pluginA", li[0])
75+
call assert_equal("packadd pluginB", li[1])
76+
call assert_equal("packadd pluginC", li[2])
77+
call assert_equal("packadd ", li[3])
78+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@ static char *(features[]) =
743743

744744
static int included_patches[] =
745745
{ /* Add new patch number below this line */
746+
/**/
747+
1492,
746748
/**/
747749
1491,
748750
/**/

src/vim.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ extern char *(*dyn_libintl_textdomain)(const char *domainname);
757757
#define EXPAND_USER 42
758758
#define EXPAND_SYNTIME 43
759759
#define EXPAND_USER_ADDR_TYPE 44
760+
#define EXPAND_PACKADD 45
760761

761762
/* Values for exmode_active (0 is no exmode) */
762763
#define EXMODE_NORMAL 1

0 commit comments

Comments
 (0)