Sublime Forum

Save and restore all opened windows

#1

Hi everybody,

I’m developing a plugin to save different sessions in Sublime Text 2. The idea of “saving a session” is to (in some way) save all the currently opened windows and its contents to a file. Then, to load a session you just need to load that file.

This plugin is quite easy to develop for one window: To save the current window, just save the content (file name, for example) of all its views. To load, just close all views and open a view for each file specified in the session file.

The problem comes when I want to save/load more than one window. I cannot find a way to close windows that are not the active one, and I also cannot open new windows programatically… I’m managing several options:

  • Save the info of the current windows in a file (for each window, save all its views. This should be enough)

  • Just serialize (pickle) the content of sublime.windows(), and load it when loading a session

  • Either modify or create several Session.sublime_session files and load/save

Any of this options seems to be valid, however as I said before, I cannot find a way to programatically open/close new windows. Can anyone help me please?

Thanks a lot!

0 Likes

#2

sublime.active_window().run_command(‘close_window’)
sublime.active_window().run_command(‘new_window’)

Discovered using sublime.log_commands(True)

0 Likes

#3

Hi adzenith,

Thanks! This works fine :smile:. I also discovered that you can do the same with sublime.run_command(‘new_window’). The only problem with these two is that they don’t return anything, like for example a reference to the new window created:

>>> w = sublime.active_window().run_command('new_window')
>>> type(w)
<type 'NoneType'>

I can figure out a way to know where is the recently opened widow (it is appended to sublime.windows()), but I was just wandering if there is a more standard/official way to do this.

Thanks for your help!

0 Likes