Home Download Buy Blog Forum Support

Preferences get lost using the API

Preferences get lost using the API

Postby kiwi on Wed Aug 07, 2013 8:33 am

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

Code: Select all
settings = sublime.load_settings(u'Preferences.sublime-settings')
ignored_packages = settings.get(u'ignored_packages', [])
if 'RestructuredText' not in ignored_packages:
   settings.set('ignored_packages', ignored_packages)

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:

Code: Select all
    'ignored_packages': [

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)
Posts: 1
Joined: Wed Aug 07, 2013 8:22 am

Re: Preferences get lost using the API

Postby Chris--- on Wed Aug 07, 2013 1:49 pm

Is working fine..

Code: Select all
>>> s = sublime.load_settings("Preferences.sublime-settings")
>>> s.get("ignored_packages")
>>> 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']
LaTeXing: LaTeX Plugin for Sublime Text 2 and 3
Posts: 25
Joined: Sat Apr 20, 2013 4:49 pm

Re: Preferences get lost using the API

Postby sapphirehamster on Thu Aug 08, 2013 4:41 pm

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
Posts: 99
Joined: Sun Jul 01, 2012 11:19 pm

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 5 guests