@@ -112,6 +112,7 @@ static int expand_showtail(expand_T *xp);
112112#ifdef FEAT_CMDL_COMPL
113113static int expand_shellcmd (char_u * filepat , int * num_file , char_u * * * file , int flagsarg );
114114static 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
116117static 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 )
0 commit comments