Kakoune code has a
BufferManager which is basically a wrapper class around a
Vector of buffers: buffer_manager.hh
To walk through this vector, the editor offers 2 basic commands
buffer-next. Internally, they both let cycle_buffer function do the heavy lifting.
There’s also the
ga command to go back and forth between 2 buffers.
The user has very little control about the order in which the buffers are stored in this vector. Over the years, a few issues were raised about this topic:
- Store buffer view history for ga (goto previous buffer)
- Keep the entire history of ‘previous buffer’
- Counter-intuitive buffers order
To summarize, the main problem from a user perspective is that it’s often not very intuitive/predictable which buffer will be displayed when
buffer-next is called.
A lot of graphical editors, display buffers in “tabs” (like “Firefox tabs”). Using the mouse, these tabs can be freely drag’n’drop, to reorder the buffers. As Kakoune is keyboard centric we have to find another paradigm.
A few ideas
Here are some proposals. They can be complementary or not. Keep in mind that they are just broad ideas, no specific details is set in stone.
- a new
sort-bufferscommand. This command can take arguments specifying how to reorder the
buffer_managervector. For example:
sort-buffers alphabeticalto reorder them by
sort-buffers pathto reorder them by filepath.
sort-buffers modifiedto reorder them by last modification date
sort-buffers filetypeto reorder them filetype
Coupled with a
-reverseswitch to decide the direction of the sorting. This
sort-bufferscommand is great for bulk reordering, but does not offer granular control.
move-buffercommand. Something like
move-buffer qux.txt -1. Example, it will have an effect like
[foo.txt, bar.txt, qux.txt]→
[foo.txt, qux.txt, bar.txt]
*buffers*buffer. By using the new
list bufferscommand, a debug
*buffers* is created. It contains the list of current buffers, with names, filetype, dates flags… By editing and then saving this special buffer, the
buffer_managervector is adapted accordingly.
I think I prefer option 3 (the interactive
*buffers*) for several reasons. Firstly, it only introduces 1 new command which is
list <arg>. This command can be useful for other purposes, for example
list registers (but that’s another topic entirely).
Secondly, the user is free to use regular Kakoune commands,
|sort or whatever tool he knows to deal with this buffer list.
What’s your take on this broad inflexible buffer-list subject?