@@ -2601,6 +2601,13 @@ buflist_findpat(
26012601 return match ;
26022602}
26032603
2604+ #ifdef FEAT_VIMINFO
2605+ typedef struct {
2606+ buf_T * buf ;
2607+ char_u * match ;
2608+ } bufmatch_T ;
2609+ #endif
2610+
26042611/*
26052612 * Find all buffer names that match.
26062613 * For command line expansion of ":buf" and ":sbuf".
@@ -2619,6 +2626,9 @@ ExpandBufnames(
26192626 char_u * p ;
26202627 int attempt ;
26212628 char_u * patc ;
2629+ #ifdef FEAT_VIMINFO
2630+ bufmatch_T * matches = NULL ;
2631+ #endif
26222632
26232633 * num_file = 0 ; /* return values in case of FAIL */
26242634 * file = NULL ;
@@ -2675,7 +2685,16 @@ ExpandBufnames(
26752685 p = home_replace_save (buf , p );
26762686 else
26772687 p = vim_strsave (p );
2678- (* file )[count ++ ] = p ;
2688+ #ifdef FEAT_VIMINFO
2689+ if (matches != NULL )
2690+ {
2691+ matches [count ].buf = buf ;
2692+ matches [count ].match = p ;
2693+ count ++ ;
2694+ }
2695+ else
2696+ #endif
2697+ (* file )[count ++ ] = p ;
26792698 }
26802699 }
26812700 }
@@ -2691,6 +2710,10 @@ ExpandBufnames(
26912710 vim_free (patc );
26922711 return FAIL ;
26932712 }
2713+ #ifdef FEAT_VIMINFO
2714+ if (options & WILD_BUFLASTUSED )
2715+ matches = ALLOC_MULT (bufmatch_T , count );
2716+ #endif
26942717 }
26952718 }
26962719 vim_regfree (regmatch .regprog );
@@ -2701,6 +2724,28 @@ ExpandBufnames(
27012724 if (patc != pat )
27022725 vim_free (patc );
27032726
2727+ #ifdef FEAT_VIMINFO
2728+ if (matches != NULL )
2729+ {
2730+ int i ;
2731+ if (count > 1 )
2732+ qsort (matches , count , sizeof (bufmatch_T ), buf_compare );
2733+ // if the current buffer is first in the list, place it at the end
2734+ if (matches [0 ].buf == curbuf )
2735+ {
2736+ for (i = 1 ; i < count ; i ++ )
2737+ (* file )[i - 1 ] = matches [i ].match ;
2738+ (* file )[count - 1 ] = matches [0 ].match ;
2739+ }
2740+ else
2741+ {
2742+ for (i = 0 ; i < count ; i ++ )
2743+ (* file )[i ] = matches [i ].match ;
2744+ }
2745+ vim_free (matches );
2746+ }
2747+ #endif
2748+
27042749 * num_file = count ;
27052750 return (count == 0 ? FAIL : OK );
27062751}
@@ -3016,7 +3061,7 @@ buflist_findlnum(buf_T *buf)
30163061 void
30173062buflist_list (exarg_T * eap )
30183063{
3019- buf_T * buf ;
3064+ buf_T * buf = firstbuf ;
30203065 int len ;
30213066 int i ;
30223067 int ro_char ;
@@ -3026,7 +3071,32 @@ buflist_list(exarg_T *eap)
30263071 int job_none_open ;
30273072#endif
30283073
3074+ #ifdef FEAT_VIMINFO
3075+ garray_T buflist ;
3076+ buf_T * * buflist_data = NULL , * * p ;
3077+
3078+ if (vim_strchr (eap -> arg , 't' ))
3079+ {
3080+ ga_init2 (& buflist , sizeof (buf_T * ), 50 );
3081+ for (buf = firstbuf ; buf != NULL ; buf = buf -> b_next )
3082+ {
3083+ if (ga_grow (& buflist , 1 ) == OK )
3084+ ((buf_T * * )buflist .ga_data )[buflist .ga_len ++ ] = buf ;
3085+ }
3086+
3087+ qsort (buflist .ga_data , (size_t )buflist .ga_len ,
3088+ sizeof (buf_T * ), buf_compare );
3089+
3090+ p = buflist_data = (buf_T * * )buflist .ga_data ;
3091+ buf = * p ;
3092+ }
3093+
3094+ for (; buf != NULL && !got_int ; buf = buflist_data
3095+ ? (++ p < buflist_data + buflist .ga_len ? * p : NULL )
3096+ : buf -> b_next )
3097+ #else
30293098 for (buf = firstbuf ; buf != NULL && !got_int ; buf = buf -> b_next )
3099+ #endif
30303100 {
30313101#ifdef FEAT_TERMINAL
30323102 job_running = term_job_running (buf -> b_term );
@@ -3100,13 +3170,23 @@ buflist_list(exarg_T *eap)
31003170 do
31013171 IObuff [len ++ ] = ' ' ;
31023172 while (-- i > 0 && len < IOSIZE - 18 );
3103- vim_snprintf ((char * )IObuff + len , (size_t )(IOSIZE - len ),
3104- _ ("line %ld" ), buf == curbuf ? curwin -> w_cursor .lnum
3173+ #ifdef FEAT_VIMINFO
3174+ if (vim_strchr (eap -> arg , 't' ) && buf -> b_last_used )
3175+ add_time (IObuff + len , (size_t )(IOSIZE - len ), buf -> b_last_used );
3176+ else
3177+ #endif
3178+ vim_snprintf ((char * )IObuff + len , (size_t )(IOSIZE - len ),
3179+ _ ("line %ld" ), buf == curbuf ? curwin -> w_cursor .lnum
31053180 : (long )buflist_findlnum (buf ));
31063181 msg_outtrans (IObuff );
31073182 out_flush (); /* output one line at a time */
31083183 ui_breakcheck ();
31093184 }
3185+
3186+ #ifdef FEAT_VIMINFO
3187+ if (buflist_data )
3188+ ga_clear (& buflist );
3189+ #endif
31103190}
31113191
31123192/*
0 commit comments