Mercurial > vim
comparison src/buffer.c @ 18463:18d7337b6837 v8.1.2225
patch 8.1.2225: the "last used" info of a buffer is under used
Commit: https://github.com/vim/vim/commit/52410575be50d5c40bbe6380159df48cfc382ceb
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Oct 27 05:12:45 2019 +0100
patch 8.1.2225: the "last used" info of a buffer is under used
Problem: The "last used" info of a buffer is under used.
Solution: Add "lastused" to getbufinfo(). List buffers sorted by last-used
field. (Andi Massimino, closes #4722)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 27 Oct 2019 05:15:06 +0100 |
parents | 6c3a8312486d |
children | 9e6d5a4abb1c |
comparison
equal
deleted
inserted
replaced
18462:395349479800 | 18463:18d7337b6837 |
---|---|
2599 else if (match < 0) | 2599 else if (match < 0) |
2600 semsg(_("E94: No matching buffer for %s"), pattern); | 2600 semsg(_("E94: No matching buffer for %s"), pattern); |
2601 return match; | 2601 return match; |
2602 } | 2602 } |
2603 | 2603 |
2604 #ifdef FEAT_VIMINFO | |
2605 typedef struct { | |
2606 buf_T *buf; | |
2607 char_u *match; | |
2608 } bufmatch_T; | |
2609 #endif | |
2610 | |
2604 /* | 2611 /* |
2605 * Find all buffer names that match. | 2612 * Find all buffer names that match. |
2606 * For command line expansion of ":buf" and ":sbuf". | 2613 * For command line expansion of ":buf" and ":sbuf". |
2607 * Return OK if matches found, FAIL otherwise. | 2614 * Return OK if matches found, FAIL otherwise. |
2608 */ | 2615 */ |
2617 buf_T *buf; | 2624 buf_T *buf; |
2618 int round; | 2625 int round; |
2619 char_u *p; | 2626 char_u *p; |
2620 int attempt; | 2627 int attempt; |
2621 char_u *patc; | 2628 char_u *patc; |
2629 #ifdef FEAT_VIMINFO | |
2630 bufmatch_T *matches = NULL; | |
2631 #endif | |
2622 | 2632 |
2623 *num_file = 0; /* return values in case of FAIL */ | 2633 *num_file = 0; /* return values in case of FAIL */ |
2624 *file = NULL; | 2634 *file = NULL; |
2625 | 2635 |
2626 /* Make a copy of "pat" and change "^" to "\(^\|[\/]\)". */ | 2636 /* Make a copy of "pat" and change "^" to "\(^\|[\/]\)". */ |
2673 { | 2683 { |
2674 if (options & WILD_HOME_REPLACE) | 2684 if (options & WILD_HOME_REPLACE) |
2675 p = home_replace_save(buf, p); | 2685 p = home_replace_save(buf, p); |
2676 else | 2686 else |
2677 p = vim_strsave(p); | 2687 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; | |
2679 } | 2698 } |
2680 } | 2699 } |
2681 } | 2700 } |
2682 if (count == 0) /* no match found, break here */ | 2701 if (count == 0) /* no match found, break here */ |
2683 break; | 2702 break; |
2689 vim_regfree(regmatch.regprog); | 2708 vim_regfree(regmatch.regprog); |
2690 if (patc != pat) | 2709 if (patc != pat) |
2691 vim_free(patc); | 2710 vim_free(patc); |
2692 return FAIL; | 2711 return FAIL; |
2693 } | 2712 } |
2713 #ifdef FEAT_VIMINFO | |
2714 if (options & WILD_BUFLASTUSED) | |
2715 matches = ALLOC_MULT(bufmatch_T, count); | |
2716 #endif | |
2694 } | 2717 } |
2695 } | 2718 } |
2696 vim_regfree(regmatch.regprog); | 2719 vim_regfree(regmatch.regprog); |
2697 if (count) /* match(es) found, break here */ | 2720 if (count) /* match(es) found, break here */ |
2698 break; | 2721 break; |
2699 } | 2722 } |
2700 | 2723 |
2701 if (patc != pat) | 2724 if (patc != pat) |
2702 vim_free(patc); | 2725 vim_free(patc); |
2726 | |
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 | |
2703 | 2748 |
2704 *num_file = count; | 2749 *num_file = count; |
2705 return (count == 0 ? FAIL : OK); | 2750 return (count == 0 ? FAIL : OK); |
2706 } | 2751 } |
2707 | 2752 |
3014 * List all known file names (for :files and :buffers command). | 3059 * List all known file names (for :files and :buffers command). |
3015 */ | 3060 */ |
3016 void | 3061 void |
3017 buflist_list(exarg_T *eap) | 3062 buflist_list(exarg_T *eap) |
3018 { | 3063 { |
3019 buf_T *buf; | 3064 buf_T *buf = firstbuf; |
3020 int len; | 3065 int len; |
3021 int i; | 3066 int i; |
3022 int ro_char; | 3067 int ro_char; |
3023 int changed_char; | 3068 int changed_char; |
3024 #ifdef FEAT_TERMINAL | 3069 #ifdef FEAT_TERMINAL |
3025 int job_running; | 3070 int job_running; |
3026 int job_none_open; | 3071 int job_none_open; |
3027 #endif | 3072 #endif |
3028 | 3073 |
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 | |
3029 for (buf = firstbuf; buf != NULL && !got_int; buf = buf->b_next) | 3098 for (buf = firstbuf; buf != NULL && !got_int; buf = buf->b_next) |
3099 #endif | |
3030 { | 3100 { |
3031 #ifdef FEAT_TERMINAL | 3101 #ifdef FEAT_TERMINAL |
3032 job_running = term_job_running(buf->b_term); | 3102 job_running = term_job_running(buf->b_term); |
3033 job_none_open = job_running && term_none_open(buf->b_term); | 3103 job_none_open = job_running && term_none_open(buf->b_term); |
3034 #endif | 3104 #endif |
3098 /* put "line 999" in column 40 or after the file name */ | 3168 /* put "line 999" in column 40 or after the file name */ |
3099 i = 40 - vim_strsize(IObuff); | 3169 i = 40 - vim_strsize(IObuff); |
3100 do | 3170 do |
3101 IObuff[len++] = ' '; | 3171 IObuff[len++] = ' '; |
3102 while (--i > 0 && len < IOSIZE - 18); | 3172 while (--i > 0 && len < IOSIZE - 18); |
3103 vim_snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), | 3173 #ifdef FEAT_VIMINFO |
3104 _("line %ld"), buf == curbuf ? curwin->w_cursor.lnum | 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 | |
3105 : (long)buflist_findlnum(buf)); | 3180 : (long)buflist_findlnum(buf)); |
3106 msg_outtrans(IObuff); | 3181 msg_outtrans(IObuff); |
3107 out_flush(); /* output one line at a time */ | 3182 out_flush(); /* output one line at a time */ |
3108 ui_breakcheck(); | 3183 ui_breakcheck(); |
3109 } | 3184 } |
3185 | |
3186 #ifdef FEAT_VIMINFO | |
3187 if (buflist_data) | |
3188 ga_clear(&buflist); | |
3189 #endif | |
3110 } | 3190 } |
3111 | 3191 |
3112 /* | 3192 /* |
3113 * Get file name and line number for file 'fnum'. | 3193 * Get file name and line number for file 'fnum'. |
3114 * Used by DoOneCmd() for translating '%' and '#'. | 3194 * Used by DoOneCmd() for translating '%' and '#'. |