ap / vim-buftabline

Forget Vim tabs – now you can have buffer tabs
http://www.vim.org/scripts/script.php?script_id=5057
MIT License
782 stars 75 forks source link

Order options for Buftabline #74

Open ewengillies opened 3 years ago

ewengillies commented 3 years ago

Hi! Love buftabline, its great.

61 already mentioned something similar, but is it possible to order the buffer-tabs alphabetically by file name? So, opening a new tab would just insert the buffer into the correct, ordered space. That, or a function that orders the tabs.

Is this possible already? Or would we need a new PR?

Thanks for the plugin :)

ap commented 3 years ago

Sorry I missed this issue entirely.

There is no such feature currently.

There are requests for several related features that so far I’ve not accepted, for reasons outlined in #8 (though only a few of those reasons apply to this issue or #61).

But your phrasing is making me think it might be doable as a hook for reordering the return value of the user_buffers function. which is an angle I don’t remember considering before, and is making me wonder whether they might all be doable in the kind of lightweight way I’d want this to be.

ewengillies commented 3 years ago

I'm not too up on my vimscript, but it looks like user_buffers filters out quickfix buffers from the buftabline display. It then returns an array of buffer numbers we want to display.

From your previous MRs, your aversion to a reordering of buffers is rooted in simplicity, and rightly so! Maintaining a registry of buffer orders would be overkill for a 200 line plugin.

If we did instead put a hook in that reordered user_buffers, I guess we still might run into limitations with bnext, bprevious, etc. in that they wouldn't know about any hook we put into user_buffers. At that point, the utility of buffers that look like tabs diminishes significantly. Is that right, or did I miss something?

ap commented 3 years ago

Mainly user_buffers filters out unlisted buffers. The point of the function is to get the list of buffers that actually represent something the user is editing – without the special-purpose buffers used by various plugins and whatnot, which should not be displayed as tabs. The utility of that should be clear.

The point is that buffers are displayed in the order that the function returns them, and it returns them in increasing buffer number order. This is the same order Vim uses anywhere it needs an ordering for buffers (such as bnext/bprevious) – so the plugin doesn’t need to provide any functionality to manage or navigate buffers. All it does is display the buffer list.

This isn’t about code bloat so much as it is about minimising the amount of user-visible functionality.

What I am now thinking is that if there was simply a hook to return the list of buffers in a user-defined order, that alone would be enough – not just to configure the display order in the plugin, but also to let users define in .vimrc whatever buffer management/navigation maps or commands they want. However, everywhere a next/previous buffer is needed, one would have to write some boilerplate code to derive it from the list, so the cherry on top would be a pair of utility functions to encapsulate that. That’s a nicely limited amount of surface area, and only exposed to users who seek it out.

Now I need to try to implement one of the requested custom orderings to see whether this design pans out in practice like it promises to in my head, and what the details should look like. (In particular whether the hook should sit inside or outside the filter in user_buffers.)

gegnew commented 3 years ago

It would be nice to allow i.e. alphabetical ordering of buftabs :+1: