[vim/vim] Sort buffers by last_used in :ls and completion (#4722)

62 views
Skip to first unread message

Andy Massimino

unread,
Jul 23, 2019, 4:07:51 PM7/23/19
to vim/vim, Subscribed

There is a buffer field last_used which is not exposed anywhere except in viminfo. This could be useful to add some features for navigating between the most recently used buffers.

Proposals (in order of increasing complexity):
- add last_used to getbufinfo for plugins to use.
- :ls t sorts buffers by last_used (most recent first) and displays the time (e.g., "3 seconds ago").
- when tab completing the :buffer command line, buffers may be displayed sorted by recency (except for current buffer).

Adequate testing is a problem because it would incur a few seconds delay.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/4722

Commit Summary

  • Sort buffers by last_used in :ls and completion

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub

Codecov

unread,
Jul 23, 2019, 4:29:57 PM7/23/19
to vim/vim, Subscribed

Codecov Report

❗️ No coverage uploaded for pull request base (master@c332816). Click here to learn what that means.
The diff coverage is 44.68%.

Impacted file tree graph

@@            Coverage Diff            @@

##             master    #4722   +/-   ##

=========================================

  Coverage          ?   81.39%           

=========================================

  Files             ?      115           

  Lines             ?   145330           

  Branches          ?        0           

=========================================

  Hits              ?   118286           

  Misses            ?    27044           

  Partials          ?        0
Impacted Files Coverage Δ
src/undo.c 83.23% <ø> (ø)
src/viminfo.c 76.63% <ø> (ø)
src/evalfunc.c 89.47% <100%> (ø)
src/buffer.c 84.13% <40%> (ø)
src/option.c 86.66% <50%> (ø)
src/ex_getln.c 76.9% <55.55%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c332816...544044d. Read the comment docs.


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub, or mute the thread.

Andy Massimino

unread,
Jul 24, 2019, 11:12:43 AM7/24/19
to vim/vim, Push

@andymass pushed 1 commit.

  • a40c211 Document getbufinfo().last_used


You are receiving this because you are subscribed to this thread.

View it on GitHub

Bram Moolenaar

unread,
Jul 27, 2019, 4:25:33 PM7/27/19
to vim/vim, Subscribed

> There is a buffer field `last_used` which is not exposed anywhere except in viminfo. This could be useful to add some features for navigating between the most recently used buffers.
>
> Proposals (in order of increasing complexity):
> - add `last_used` to getbufinfo for plugins to use.
> - `:ls t` sorts buffers by `last_used` (most recent first) and displays the time (e.g., "3 seconds ago").
> - when tab completing the `:buffer ` command line, buffers may be displayed sorted by recency (except for current buffer).

Sounds useful.


> Adequate testing is a problem because it would incur a few seconds delay.

You can use test_settime() for this.


--
BEDEVERE: And what do you burn, apart from witches?
FOURTH VILLAGER: ... Wood?
BEDEVERE: So why do witches burn?
SECOND VILLAGER: (pianissimo) ... Because they're made of wood...?
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Bram Moolenaar

unread,
Sep 9, 2019, 3:19:47 PM9/9/19
to vim/vim, Subscribed

This needs to be synced with head. And please add a test, using test_settime() should work.

Justin M. Keyes

unread,
Sep 9, 2019, 5:02:33 PM9/9/19
to vim/vim, Subscribed

@justinmk commented on this pull request.


In src/undo.c:

> @@ -3107,7 +3106,7 @@ ex_undolist(exarg_T *eap UNUSED)
 /*
  * Put the timestamp of an undo header in "buf[buflen]" in a nice format.
  */
-    static void
+    void
 u_add_time(char_u *buf, size_t buflen, time_t tt)

This is no longer undo-specific.

Justin M. Keyes

unread,
Sep 9, 2019, 5:05:40 PM9/9/19
to vim/vim, Subscribed

@justinmk commented on this pull request.


In runtime/doc/eval.txt:

> @@ -4457,6 +4457,9 @@ getbufinfo([{dict}])
 			changed		TRUE if the buffer is modified.
 			changedtick	number of changes made to the buffer.
 			hidden		TRUE if the buffer is hidden.
+			last_used	time in seconds when the buffer was
+					last used.
+					{only with the |+viminfo| feature}

I would remove the underscore. Because changedtick doesn't have one, and for parallel with list:lastused.

Mark Manning

unread,
Sep 9, 2019, 5:06:04 PM9/9/19
to vim...@googlegroups.com
I was looking at the freeBasic.vim file and found some errors in it.
Where do I upload it to? It has been so long I've forgotten. :-/

Mark

Christian Brabandt

unread,
Sep 10, 2019, 3:00:44 AM9/10/19
to vim...@googlegroups.com

On Mo, 09 Sep 2019, Mark Manning wrote:

> I was looking at the freeBasic.vim file and found some errors in it. Where
> do I upload it to? It has been so long I've forgotten. :-/

Are you talking about runtime/syntax/freebasic.vim? You seem to be the
maintainer, so simply send an updated version to Bram for inclusion with
the next runtime files update.

Thanks,
Christian
--
"Nachdenken und Handeln verglich einer mit Rahel und Lea: Die
eine war anmutiger, die andere fruchtbarer."
-- Goethe, Maximen und Reflektionen, Nr. 162

Bram Moolenaar

unread,
Sep 10, 2019, 3:23:48 PM9/10/19
to vim...@googlegroups.com, Mark Manning

Mark Manning wrote:

> I was looking at the freeBasic.vim file and found some errors in it.
> Where do I upload it to? It has been so long I've forgotten. :-/

You can email me the new version. It's that simple.

--
hundred-and-one symptoms of being an internet addict:
235. You start naming your kids Pascal, COBOL, Algol and Fortran.

Bram Moolenaar

unread,
Sep 10, 2019, 3:57:59 PM9/10/19
to vim/vim, Subscribed

@brammool commented on this pull request.


In runtime/doc/eval.txt:

> @@ -4457,6 +4457,9 @@ getbufinfo([{dict}])
 			changed		TRUE if the buffer is modified.
 			changedtick	number of changes made to the buffer.
 			hidden		TRUE if the buffer is hidden.
+			last_used	time in seconds when the buffer was
+					last used.
+					{only with the |+viminfo| feature}

Agree

Andy Massimino

unread,
Sep 13, 2019, 7:31:11 AM9/13/19
to vim/vim, Subscribed

Thanks for the comments, writing tests now. Do we know what the definition of "last used" is? Does having a buffer open in a window without editing count? E.g. what if I open a buffer at 3:00, do nothing, and switch to another buffer at 7:00? What about hidden buffers? Does it matter if a buffer is new or existing?

Andy Massimino

unread,
Sep 21, 2019, 8:15:04 AM9/21/19
to vim/vim, Push

@andymass pushed 1 commit.


You are receiving this because you are subscribed to this thread.

View it on GitHub

Andy Massimino

unread,
Sep 21, 2019, 9:45:25 AM9/21/19
to vim/vim, Subscribed

Tests added

Bram Moolenaar

unread,
Oct 27, 2019, 12:13:19 AM10/27/19
to vim/vim, Subscribed

Closed #4722 via 5241057.


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub, or unsubscribe.

Reply all
Reply to author
Forward
0 new messages