@@ -121,6 +121,14 @@ static int ExpandUserList __ARGS((expand_T *xp, int *num_file, char_u ***file));
121121static int ex_window __ARGS ((void ));
122122#endif
123123
124+ #if defined(FEAT_CMDL_COMPL ) || defined(PROTO )
125+ static int
126+ #ifdef __BORLANDC__
127+ _RTLENTRYF
128+ #endif
129+ sort_func_compare __ARGS ( (const void * s1 , const void * s2 ));
130+ #endif
131+
124132/*
125133 * getcmdline() - accept a command line starting with firstc.
126134 *
@@ -3286,6 +3294,24 @@ ccheck_abbr(c)
32863294 return check_abbr (c , ccline .cmdbuff , ccline .cmdpos , 0 );
32873295}
32883296
3297+ #if defined(FEAT_CMDL_COMPL ) || defined(PROTO )
3298+ static int
3299+ #ifdef __BORLANDC__
3300+ _RTLENTRYF
3301+ #endif
3302+ sort_func_compare (s1 , s2 )
3303+ const void * s1 ;
3304+ const void * s2 ;
3305+ {
3306+ char_u * p1 = * (char_u * * )s1 ;
3307+ char_u * p2 = * (char_u * * )s2 ;
3308+
3309+ if (* p1 != '<' && * p2 == '<' ) return -1 ;
3310+ if (* p1 == '<' && * p2 != '<' ) return 1 ;
3311+ return STRCMP (p1 , p2 );
3312+ }
3313+ #endif
3314+
32893315/*
32903316 * Return FAIL if this is not an appropriate context in which to do
32913317 * completion of anything, return OK if it is (even if there are no matches).
@@ -4735,7 +4761,16 @@ ExpandGeneric(xp, regmatch, num_file, file, func, escaped)
47354761
47364762 /* Sort the results. Keep menu's in the specified order. */
47374763 if (xp -> xp_context != EXPAND_MENUNAMES && xp -> xp_context != EXPAND_MENUS )
4738- sort_strings (* file , * num_file );
4764+ {
4765+ if (xp -> xp_context == EXPAND_EXPRESSION
4766+ || xp -> xp_context == EXPAND_FUNCTIONS
4767+ || xp -> xp_context == EXPAND_USER_FUNC )
4768+ /* <SNR> functions should be sorted to the end. */
4769+ qsort ((void * )* file , (size_t )* num_file , sizeof (char_u * ),
4770+ sort_func_compare );
4771+ else
4772+ sort_strings (* file , * num_file );
4773+ }
47394774
47404775#ifdef FEAT_CMDL_COMPL
47414776 /* Reset the variables used for special highlight names expansion, so that
0 commit comments