E_NO_SUCH_BLOG

Programming, philosophy, pedaling.


Session Management in Sublime Text

Nov 1, 2015

Tags: programming, workflow

I’ve spent a lot of time switching between editors.

Vim was my editor of choice for roughly three years, followed by two years of switching between a wide range of open and proprietary offerings including TextWrangler, Textadept, and Sublime Text 2.

I finally settled on Sublime Text 3 about a year ago, and it’s treated me fairly well - I spend (relatively) less time fiddling with configurations and settings, and more time fiddling with my programs.

There has, however, been one exception to this: Sublime Text’s abysmal support for sessions (or projects, or workspaces, or whatever you call them). By default, Sublime Text manages sessions with .sublime-project and .sublime-workspace files, which have to be opened manually (Project -> Open Project…) and contain a mess of session context and history that Sublime Text can regenerate automatically anyways. Sublime also stores its global state in its project files, making it impossible to work on multiple projects at once without saving all of them in a single workspace.

I normally work on 2 to 4 projects at any given time, so this simply wasn’t acceptable for me. I had worked around it for months by dedicating entire workspaces in my window manager to each project, but this became cumbersome and required me to reorganize and reconstruct all of my workspaces each time I exited Sublime.

Sublime Text’s package ecosystem is fairly comprehensive, aided by Will Bond’s excellent package manager. Unfortunately, I could only find one package with functionality even remotely close to what I wanted: Sascha Wolf’s Session Manager.

Session Manager fixes a few flaws in Sublime’s default session management (like the obtuse file-based interface), but also brings in a few of its own. In particular, it likes to create a new window every time a session is loaded (even when the current window is empty), and doesn’t preserve window layout or grouping across loads (making multi-row/column windows collapse into one giant collection of tabs).

This was unacceptable for my purposes, so I created my own (tiny) session management package, the aptly named SimpleSession. At 122 lines of Python, SimpleSession accomplishes something that none of the other session managers for Sublime Text could: per-window session management and layout preservation, all with mappable commands and command palette integration. SimpleSession’s session files are also extremely simple: nothing more than a JSON formatted array of file groups and window layout parameters.

A quick demo:

(Please forgive the window creation stutter - I think it’s my graphics drivers.)

SimpleSession is currently available on Package Control, as well as in a GitHub repository. If you’ve been looking for something like this in Sublime Text (as I have, for quite a while), feel free to give it a try. I’d also love to hear any feedback - what more (or less) it should do, and how it should do it (my Python is pretty rusty).

- William