Skip to content

@agibsonsw /SortTabs.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Sort Tabs (Window Command)
import sublime, sublime_plugin
from os import path
from operator import itemgetter
class SortTabsCommand(sublime_plugin.WindowCommand):
def run(self):
file_views = []
win = self.window
curr_view = win.active_view()
for vw in win.views():
_, tail = path.split(vw.file_name() or path.sep)
group, _ = win.get_view_index(vw)
file_views.append((tail.lower(), vw, group))
file_views.sort(key = itemgetter(2, 0))
for index, (_, vw, group) in enumerate(file_views):
if index == 0 or group > prev_group:
moving_index = 0
prev_group = group
else:
moving_index += 1
win.set_view_index(vw, group, moving_index)
win.focus_view(curr_view)
@agibsonsw
Owner

Sorting tabs should really be a WindowCommand, as it applies to the Window as a whole. Andy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.