Skip to content

Instantly share code, notes, and snippets.

@agibsonsw
Created March 7, 2012 19:37
Show Gist options
  • Save agibsonsw/1995446 to your computer and use it in GitHub Desktop.
Save agibsonsw/1995446 to your computer and use it in GitHub Desktop.
ST navigate sorted files (neater)
import sublime, sublime_plugin, os, datetime
from operator import itemgetter
file_views = []
class OrderedFilesCommand(sublime_plugin.TextCommand):
def run(self, edit, index):
global file_views
file_views = []
win = self.view.window()
for vw in win.views():
head, tail = os.path.split(vw.file_name())
modified = os.path.getmtime(vw.file_name())
file_views.append((tail, vw, modified))
if index == 0:
file_views.sort(key = lambda (tail, Doh, Dur): tail.lower())
win.show_quick_panel([x for (x, y, z) in file_views], self.on_chosen)
else:
file_views.sort(key = itemgetter(2))
win.show_quick_panel([
(datetime.datetime.fromtimestamp(z)).strftime("%d-%m-%y %H:%M ") + x \
for (x, y, z) in file_views], self.on_chosen)
def on_chosen(self, index):
if index != -1:
win = self.view.window()
win.focus_view(file_views[index][1])
@agibsonsw
Copy link
Author

No change in function, just slightly tidier code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment