Sublime Forum

Help with saving settings


I have a custom plugin that lives in …AppData\Roaming\Sublime Text 3\Packages<plugin> folder. I also have a .sublime-settings file in this folder that has some configurable settings. I get user input and update the settings file using the following APIs:

s = sublime.load_settings(.sublime-settings)
s.set("_%s" %key, value)

However, I notice that instead of updating the settings in my folder, it actually creates a new file in …AppData\Roaming\Sublime Text 3\Packages\User and saves the settings.

What am I missing?




That is correct. Settings applied programmatically are saved in the User folder. Other package folders are not written to via a settings object.



Thanks Will.



Could you kindly explain Why this Limitation exists?



It’s not a limitation. It’s how the API (sublime.save_settings()) works.

Any package that ships with a settings file e.g. MyCoolPackage.sublime-settings, ships it with what that package considers as some base, default value(s) for those setting(s) that theoretically every user can be comfortable with (depending on the functionality of the package).

When the save_setting() function is called, it shouldn’t modify the original package settings file as that is the default and used for reference. Any changes to the package settings should be stored in a file by the same name in User (which is your personal universe for settings, plugins, and everything custom).

This way not only are the default presets preserved, the package settings file in User also gets precedence over the default package setting file and those changes are applied, so every user can customize the package settings (in turn the package behavior) to their liking.

Hopefully this explains why it is the way it is.