Sublime Forum

Re-open tabs only when working in a project

#1

I’ve been using sublime for ages, but I’ve never been a power user, so I’ve never really used workspaces or projects. With some reading, I found out that projects basically just are a list of folders (and some included/excluded stuff), and workspaces are the tabs you’ve got open (right?).

When I’m not working in a project, I’d like sublime to exit cleanly, so without keeping anything open (achieved by setting hot_exit to false).

However, when I open a project, I would like sublime to open the files / tabs I had open the last time, preferably without me having to specifically save these open tabs before closing, since I’m gonna forget that every time. Is something like this possible?

0 Likes

#2

I don’t think this is directly possible, though a plugin may help.

When hot_exit is turned off, Sublime doesn’t persist any session information at all on exit; not for projects and also not for windows with anonymous project data. So with it on, the state for your main window will be persisted when you don’t want it to be, and with it off projects won’t save state when you’re done with them.

With hot_exit off, you would need to remember to use Project > Close Project when you’re done with a project, which will persist the state in the session. Forgetting to do that will lose the current state.

With hot_exit on, windows with anonymous project data will persist when you don’t want them to (basically any window that doesn’t have a sublime-project file associated with it). In order to get back to a “clean” state in this case you would need to do something like close all the files/folders in the window, or create a new empty window and then close the existing window(s).

You could leave hot_exit turned on and then have a plugin trigger when Sublime starts up that closes all of the existing windows (potentially force-closing all unsaved files in non-project windows) and leave you with one new empty window., though.

0 Likes

#3

Thank you for your extensive reply.
Given that you don’t mention any plugin specifically, I assume that something like that doesn’t exist at the moment?

0 Likes

#4

There may be something that does that on Package Control, but I’m not aware of any offhand. Closing windows and files is easy to do though, so if you can provide a bit more detail on how you’d like it to work it should be fairly quick to whip something up.

For example, would you like Sublime to always open to a clean, empty window, even if that means closing all of the windows that it opens with (whether they contain projects or not)? What should happen if one of the windows that doesn’t contain a project has unsaved files in it; should you be prompted to save them or would you just like them to be clobbered away?

0 Likes

#5

If possible, I would prefer to be prompted about unsaved files when I close sublime. When I open sublime regularly, I’d like it to start clean (so just a new file, or the single file I opened). When I open a project (either by clicking the .sublime-project file, or ‘project>open project’), I would like sublime to open as if I clicked on ‘close project’ before exiting sublime the last time I worked in that project, so with the files open that were open the last time I worked on it.

0 Likes

#6

For any state to be persisted at all hot_exit needs to be turned on, which precludes the ability to be asked close all of the files in non-project windows because there’s not currently a way to reliably detect when Sublime is being terminated (essentially you would need to dedicate yourself to always using a specific key binding or menu item to quit and never do something like try to close the last window).

0 Likes

#7

Hm, that’s a shame. Thank you for your input.

0 Likes