Sublime Forum

Help with saving settings

#1

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)
sublime.save_settings(.sublime-settings)

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?

Rajah

0 Likes

#2

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

2 Likes

#3

Thanks Will.

0 Likes

#4

Could you kindly explain Why this Limitation exists?

0 Likes

#5

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.

0 Likes