Sublime Forum

Using settings for session data

#1

I have data that’s I’d like to associate with a “session.”

If the window has a project, I’d want to associate the data with the window.

If the window doesn’t have a project, I’d want to associate the data with each (relevant) view in a window.

By “session” I mean that this stuff that relates to the plugin while it’s running. This isn’t, for example, stuff that I’d ever expect or want users to enter in, say, a settings file. And it’s stuff that I can re-create as needed.

My question is: can I use window.settings() and view.settings() for this?

If the answer is “no” then it means that I’ll have data associated with open windows and open views, and I’ll have to take responsibility for keeping things in sync — e.g., unloading the data when the associated window (or view) closes.

That’s doable, but if I add the data to settings then Sublime does it for me. Not just that: Sublime is sure to get it right. Me getting it right relies on having a very solid understanding of the various events. As a plugin newbie, well, I’m not there yet. :slight_smile:

(The session data I’m talking about is dicts of lists of strings that are used for completions.)

I don’t expect the data to be big, though that’s clearly subjective.

And I would store it in memory regardless.

This is all coming up because I don’t want to store it in memory longer than it’s actually needed. Which is what I’m doing right now.

0 Likes

#2

I recently discovered that window.settings() is survives ST restart, so yes, you can use it to store things like session data (typically cache).

For things more important than cache (and also because I didn’t know window.settings() was persistent) I personally save (JSON) data to disk on exit, ad read it on ST startup.

view.settings() on the other hand is not persistent, and is discarded after the view is closed.

1 Like

#3

view settings are persisted in the same way window settings are persisted; as long as the view/window stays open when hot exiting then they’ll get restored. If hot exit is disabled of course those aren’t persisted.

1 Like

#4

OK, I think I understand, thank you.

0 Likes