@@ -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
@@ -4242,6 +4243,7 @@ addstar(
42424243 || context == EXPAND_COMPILER
42434244 || context == EXPAND_OWNSYNTAX
42444245 || context == EXPAND_FILETYPE
4246+ || context == EXPAND_PACKADD
42454247 || (context == EXPAND_TAGS && fname [0 ] == '/' ))
42464248 retval = vim_strnsave (fname , len );
42474249 else
@@ -4658,6 +4660,8 @@ ExpandFromContext(
46584660 if (xp -> xp_context == EXPAND_USER_LIST )
46594661 return ExpandUserList (xp , num_file , file );
46604662# endif
4663+ if (xp -> xp_context == EXPAND_PACKADD )
4664+ return ExpandPackAddDir (pat , num_file , file );
46614665
46624666 regmatch .regprog = vim_regcomp (pat , p_magic ? RE_MAGIC : 0 );
46634667 if (regmatch .regprog == NULL )
@@ -5194,6 +5198,58 @@ ExpandRTDir(
51945198 return OK ;
51955199}
51965200
5201+ /*
5202+ * Expand loadplugin names:
5203+ * 'packpath'/pack/ * /opt/{pat}
5204+ */
5205+ static int
5206+ ExpandPackAddDir (
5207+ char_u * pat ,
5208+ int * num_file ,
5209+ char_u * * * file )
5210+ {
5211+ char_u * s ;
5212+ char_u * e ;
5213+ char_u * match ;
5214+ garray_T ga ;
5215+ int i ;
5216+ int pat_len ;
5217+
5218+ * num_file = 0 ;
5219+ * file = NULL ;
5220+ pat_len = (int )STRLEN (pat );
5221+ ga_init2 (& ga , (int )sizeof (char * ), 10 );
5222+
5223+ s = alloc ((unsigned )(pat_len + 26 ));
5224+ if (s == NULL )
5225+ {
5226+ ga_clear_strings (& ga );
5227+ return FAIL ;
5228+ }
5229+ sprintf ((char * )s , "pack/*/opt/%s*" , pat );
5230+ globpath (p_pp , s , & ga , 0 );
5231+ vim_free (s );
5232+
5233+ for (i = 0 ; i < ga .ga_len ; ++ i )
5234+ {
5235+ match = ((char_u * * )ga .ga_data )[i ];
5236+ s = gettail (match );
5237+ e = s + STRLEN (s );
5238+ mch_memmove (match , s , e - s + 1 );
5239+ }
5240+
5241+ if (ga .ga_len == 0 )
5242+ return FAIL ;
5243+
5244+ /* Sort and remove duplicates which can happen when specifying multiple
5245+ * directories in dirnames. */
5246+ remove_duplicates (& ga );
5247+
5248+ * file = ga .ga_data ;
5249+ * num_file = ga .ga_len ;
5250+ return OK ;
5251+ }
5252+
51975253#endif
51985254
51995255#if defined(FEAT_CMDL_COMPL ) || defined(FEAT_EVAL ) || defined(PROTO )
@@ -5741,6 +5797,7 @@ clr_history(int histype)
57415797 {
57425798 vim_free (hisptr -> hisstr );
57435799 clear_hist_entry (hisptr );
5800+ hisptr ++ ;
57445801 }
57455802 hisidx [histype ] = -1 ; /* mark history as cleared */
57465803 hisnum [histype ] = 0 ; /* reset identifier counter */
0 commit comments