Sublime Forum

Preferences get lost using the API

#1

Using the API, User Preferences get overridden on restart using following code:

settings = sublime.load_settings(u'Preferences.sublime-settings')
ignored_packages = settings.get(u'ignored_packages', ])
if 'RestructuredText' not in ignored_packages:
	ignored_packages.append(u'RestructuredText')
	settings.set('ignored_packages', ignored_packages)
	sublime.save_settings(u'Preferences.sublime-settings')

This code is intended to add “RestructuredText” to ignored_packages (and of course keep the other User-Preferences).
But it results in having following User/Preferences.sublime-settings:

{
    'ignored_packages':  
        'RestructuredText'
    ]
}

Have I misunderstood the API or is this behaviour a bug?

(I finally solved it using json module and directly reading and writing “User/Preferences.sublime-settings”, but I
expected the API doing it)

0 Likes

#2

Is working fine…

>>> s = sublime.load_settings("Preferences.sublime-settings")
>>> s.get("ignored_packages")
'Vintage']
>>> l = s.get("ignored_packages")
>>> l.append("RestructuredText")
>>> s.set("ignored_packages", l)
ignored packages updated to: [Vintage, RestructuredText]
>>> sublime.save_settings("Preferences.sublime-settings")
>>> s.get("ignored_packages")
'Vintage', 'RestructuredText']
0 Likes

#3

I think the load_settings API is intended for your own plugin’s settings file, not the ones that are part of Sublime (which you access via view.settings). Maybe reading this will help you understand more about how settings work: viewtopic.php?f=6&t=9076#p36601

0 Likes