Sublime Forum

Save setting to workspace

#1

i would like to toggle and remember a setting in ST3 using sublime workspace instead of preference settings, so the state is known even after restarting ST. Is this possible?

0 Likes

#2

There are a couple of ways to do this, depending on what you’re trying to achieve.

The state of open files is maintained in the session, so if you were to say view.settings().set("some_key", "some_value"), that setting will persist as long as the file is open, including across restarts in the session. It will however be lost when the file is closed.

Alternately, you can also do window.settings().set("some_key", "some_value") and the setting will associate with the window instead. That will also persist in the session (or workspace, depending on if you’re using a project or not) and come back after a restart.

If you do it for a normal window, it will be lost when that window closes, though if you’re using a project it will remain for the life of the project.

For anything else, you want to use either a sublime-settings file somewhere, or store a file yourself somewhere, such as in the User package (but generally speaking, sublime-settings files are easier and will automagically update their values for you).

1 Like