issue151: Reorder tabs or buffers

Priority: wish Status: resolved
msg331 (view) Author: dclemente Date: 2009-04-27.18:12:53
I would like to move a tab (from new-tabs.js) one position to the left or to the right. Maybe it's easier
to change the order of the buffers, not the tabs, so that C-x b (switch_to_buffer) shows also the new order. 

Some code and implementation ideas are in this thread:
msg791 (view) Author: arlinius Date: 2011-01-12.02:53:06
I have a working implementation of this at

To use it, bind keys to buffer-move-forward and buffer-move-backward.

Please test and comment.

From the commit log for commit 5559d7e138f24155ea1575e4779ebff835520d2d:

added support for re-ordering buffers and tabs

Tabs no longer have closures on their buffers. Instead, a tab's
buffer is now stored as a property of the tab. Also fixed some
whitespace in tab.addEventListener calls.

The buffer container now has a buffer_ordering list which
specifies the order of the buffers used for buffer_next, rather
than using the order of the buffer vbox elements in the
buffer-container deck directly.

A new function, buffer_move_forward, has been added. This
function moves a buffer forward in its window's buffer
container. The interactive commands buffer-move-forward and
buffer-move-backward have also been added. There is a new hook,
move_buffer_hook, which is run every time the order of buffers is
changed. Its argument is the buffer that was moved.

new-tabs.js uses move_buffer_hook to update the index numbers
shown on the tabs as well as the ordering of the tabs. Tab
ordering is controlled by setting the ordinal attribute on the
msg804 (view) Author: dclemente Date: 2011-01-28.10:23:09
Thanks for implementing this. I have been testing it and it works pretty well.
  - I would add  this.add_hook("move_buffer_hook") in buffer_count_widget (mode-line.js) to update the
„[13/13]“ part in the modeline.
  - Each reordering should be written to the session file. Now, if I change the order of a tab and close
Conkeror without adding/removing other tabs, the original ordering is saved. So session_auto_save_save
should be run in move_buffer_hook too
  - It doesn't work when the tab bar is disabled, due to move_buffer_hook always calling
tab_bar_move_buffer. I suppose it could rearrange buffers so that you'll notice those invisible changes
when you turn the tab bar on again.
msg849 (view) Author: dclemente Date: 2011-05-11.06:53:02
This basically works, so it could be included in conkeror.
msg850 (view) Author: retroj Date: 2011-05-11.17:04:39
I've got another implementation of this feature which I prefer, because this one has a few bugs.  Will
try to finish it up soon, since there is demand for the feature.  (Have been mainly working on another
branch which has a completely different model of how buffers work.)  Sorry, won't accept 'basically works'
for a fundamental change to the GUI design.
msg855 (view) Author: retroj Date: 2011-05-14.19:41:30
An implementation is now ready for beta-testing in the 'buffer-ordering' branch of our main git repo:

Adding buffer moving has deeper implications to the coherency of the UI than one might imagine, and
there was a major problem that needed to be addressed.  It is that we have a certain amount of
infrastructure built around the idea that buffers are primarily ordered by their access time, like in
emacs.  Buffer moving introduces explicitly what tabs only introduced implicitly: that buffers have
spatial relationships to each other.  If buffer moving is not done right, we end up with two
competing and incompatible subsystems for ordering buffers, and it winds up making the UI illogical
and increasingly complex as new users come along with requests for new ways of ordering buffers.

Consider the command 'bury-buffer', which affects the temporal ordering of buffers.  If buffers are
to have an explicit spatial ordering, then bury-buffer must act on this ordering or become
irrelevant.  This means that there must be a _place_ to bury buffers.  The end of the buffer list is
the natural choice, but this conflicts with the default ordering of buffers: that new buffers are
created at the end of the list, in "buried" position. The way out of the conflict is to modify default
buffer ordering:

 * New buffers opened by url or webjump (thus having no "opener" buffer) are created at the front of
   the list instead of the end.

 * New buffers opened by link or other DOM object are created immediately to the right of the buffer
   that contained the link or object, which is called the opener buffer.

The keys M-N and M-P are used to move buffers manually through the spatial buffer list.

The implementation is also done mindful of flexibility for users that want to order buffers
differently.  Configuration points have not yet been added, as this is itself a complex issue needing
careful thought, but adding them to the code as it exists should not be difficult.
msg981 (view) Author: retroj Date: 2012-01-29.20:18:43
done.  final design described at
Date User Action Args
2012-01-29 20:18:43retrojsetstatus: testing -> resolved
messages: + msg981
2011-05-14 19:41:30retrojsetmessages: + msg855
2011-05-11 17:04:39retrojsetmessages: + msg850
2011-05-11 06:53:02dclementesetmessages: + msg849
2011-01-28 10:23:09dclementesetmessages: + msg804
2011-01-12 02:53:06arliniussetstatus: unread -> testing
messages: + msg791
2009-04-27 18:12:53dclementecreate