Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lastused property for windows/buffers/tabpages ("MRU history") #28745

Open
kkrime opened this issue May 14, 2024 · 5 comments · May be fixed by #28742
Open

lastused property for windows/buffers/tabpages ("MRU history") #28745

kkrime opened this issue May 14, 2024 · 5 comments · May be fixed by #28742
Labels
enhancement feature request
Milestone

Comments

@kkrime
Copy link

kkrime commented May 14, 2024

Problem

I'm trying to add a lastused property to vim.fn.getwininfo, like in vim.fn.getbufinfo.

It's just a timestamp for when a windown was last entered into

I've made a start: #28742 and for the most part it works, however, there's one case where it doesn't work as expected;

If a buffer is opened in multiple windows, the timestamp (w_last_used) won't get updated when you enter any of the other windows, apart from the first window that the buffer was opened in and all the windows display the same timestamp as the first window.

Please note I'm completly new to this codebase and any help to pointing me to the right direction, or just any tips/guidance in general would be greatly appreciated

Background

In case anyone is curious as to why I want this;

It's to do with the qf window, specifically what happens when you select an item in the qf window that's open in multiple windows.

When I'm developing, I may have multiple windows open of the same buffer (due to me jumping around the code).

If there's an item in the qf window that's open in multiple windows, I would like that item to open in the windown that was most reccently accessed, see; https://github.com/kevinhwang91/nvim-bqf/pull/140/files

Expected behavior

I expect each window to have it's timestamp updated each time I enter it

@kkrime kkrime added the enhancement feature request label May 14, 2024
@kkrime kkrime linked a pull request May 14, 2024 that will close this issue
@justinmk
Copy link
Member

This is related to a more general idea, which is that currently it's clumsy and unreliable to get a history of accesses ("touches"/"last-used"/"recent") to buffers/windows/tabpages.

Cross-posting from #28742 (comment) :

I think we clearly want last-used history, and last_used: datetime could avoid maintaining an extra ringbuffer for each object type.

So instead of:

histget('win')
histget('buf')
histget('tabpage')

users/plugins could get the last-used history by sorting on last_used. And even if we provide histget('win'), that could internally use the same approach.

Use-cases: Having a history of last-used bufs/wins/tabs would

  • improve the behavior of g<tab>
  • helps implement ZB (delete buffer without losing split)
  • helps implement histget('win'), histget('buf'), etc.

Caveat: multple windows could have the same last_used timestamp, then the "history" is not 100% reliable. But storing microsecond-granularity should be good enough.

@justinmk justinmk added this to the backlog milestone May 14, 2024
@justinmk justinmk changed the title Adding lastused property to windows lastused property to windows/buffers/tabpages ("MRU history") May 14, 2024
@justinmk justinmk changed the title lastused property to windows/buffers/tabpages ("MRU history") lastused property for windows/buffers/tabpages ("MRU history") May 14, 2024
@kkrime
Copy link
Author

kkrime commented May 15, 2024

I've done some more digging into this and started to realize the scale of my naivety about this change....

In short, it looks like entering_window()

void entering_window(win_T *const win)
gets used a lot.

I created a counter for each window to keep track when a window_entered() is called for any given window and it looks like when just writing a file alone window_entered() gets called 17 times!

What's the likelihood that entering_window() can be extended to have an aditional parameter something like;

void entering_window(win_T *const win, user_command bool)

where user_command bool signifies that the call to window_entered() was as a result of a user action or not.

Do you think this change or somerthing similar would be OK to make or do you think would I face objections to this?

@zeertzjq
Copy link
Member

I don't think that's better than adding the code somewhere else outside that function.

@kkrime
Copy link
Author

kkrime commented May 15, 2024

@zeertzjq where do you think it would be best to add a user_command flag and set the w_last_used timestamp?

@zeertzjq
Copy link
Member

I don't think that flag is needed if you move the code out of entering_window().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants