Brief version:
With hot_exit enabled, Sublime Text saves unsaved changes to the session, but not to the project’s *.sublime-workspace file.
To avoid the kinds of data loss I’ve experienced, I feel like Sublime Text should be saving to the project’s workspace when the application is closed (where ‘hot_exit’: true).
Is there a setting I’m missing, or some way I can change this behaviour?
Also, I can’t think of any use case where it would be bad to save the workspace to the *.sublime-workspace file (where ‘hot_exit’: true), but I’m interested in hearing if there’s a particular rationale behind the current behaviour.
Note: This post is referencing Sublime Text 3 (ST3), as I haven’t yet made the switch to version 4. If the hot_exit behaviour is different/better/customisable in ST4, I’m keen to hear what has changed.
Full version:
One thing I love about Sublime Text is the hot_exit function. It’s particularly good for my notes project, which I use as a scratchpad. It means I can dump snippets of text into an open tab, and decide later whether to discard, save to a file, or paste somewhere else such as Evernote.
One thing I don’t like is that I occasionally lose data, due to the way hot_exit works. I’ve had a look through various other posts discussing hot_exit and the way workspaces function, but I didn’t spot any that got to the heart of the issue I’m seeing, so I’ll try to outline it in this post.
With hot_exit set to true:
- Closing a project window causes unsaved changes to be saved in the workspace (e.g. notes.sublime-workspace). Awesome!
- Closing the entire application (Quit/Exit) causes unsaved changes to be saved to Session.sublime_session, but not to the workspace.
In theory, that’s okay, right? You start Sublime Text again, everything is restored as it was, and when you eventually close the project window, notes.sublime-workspace gets updated then.
In practice, there are use cases where I lose data:
- When the project files (including notes.sublime-workspace) are not available when Sublime Text starts. (E.g. they’re on drive that’s unplugged or a volume that’s not yet mounted.) In this case, all the open tabs and unsaved work that Sublime Text saved in the session suddenly disappear.
- When I want to work with the project (synchronised via Dropbox) on a different computer. In this case, I close Sublime Text at the office, open the project at home, and wonder where my recent work is.
I’ve trained myself to (mostly) avoid the latter; now that I know ST3 doesn’t actually write to notes.sublime-workspace on exit, I usually remember to first close the project window and check that the Dropbox sync is picking up the change.
The former I’ve just encountered today. After a computer restart, I made the mistake of opening Sublime Text before remembering that I hadn’t yet mounted the volume that contained my project. Since I normally leave my notes project open all the time, a week’s worth of changes disappeared due to there being no trigger to save changes to the notes.sublime-workspace.
Related details, for context:
Whilst trying to better understand the issue, I discovered that the hot_exit preference is what tells ST3 to write unsaved changes to either the workspace (when closing a project window) or the session (when closing the application).
I found this clear information about the hot_exit function in the preferences:
// Exiting the application with hot_exit enabled will cause it to close
// immediately without prompting. Unsaved modifications and open files will
// be preserved and restored when next starting.
//
// Closing a window with an associated project will also close the window
// without prompting, preserving unsaved changes in the workspace file
// alongside the project.
"hot_exit": true,
The first comment accurately says that “unsaved modifications and open files will be preserved”, but it doesn’t say where.
I did some digging and found that it’s preserving to a session file (~/.config/sublime-text-3/Local/Session.sublime_session on my Linux Mint computer).
What I can’t see is:
- Any setting to tell Sublime Text to save to the workspace file (where one exists) rather than the session.
- Anything in the Command Palette to manually trigger preserving unsaved modifications and open files to the active workspace file (i.e. without having to select “Save Workspace As…” and agree to overwrite the file).
- Any reason that saving to the session might be preferable to saving to the project’s workspace file.