Home Download Buy Blog Forum Support

Read and write custom settings file

Read and write custom settings file

Postby jbrooksuk on Wed Aug 31, 2011 9:20 am

I pretty much suck with Python, so be nice :)

How can I implement a custom settings file into my plugin, so that the user can add their own values, then my plugin read them later on?

JSON would be the best way of storing them, to keep in sync with the rest of Sublime.
jbrooksuk
 
Posts: 775
Joined: Sun Apr 11, 2010 10:37 am
Location: England

Re: Read and write custom settings file

Postby jbjornson on Wed Aug 31, 2011 9:25 am

You should be able to use something like this to load, save and access your settings:

Code: Select all
    history_filename = 'YourPluginName.sublime-settings'
    history = sublime.load_settings(history_filename)
    history.set("some_key", "some_value")
    value = history.get("some_key")
    sublime.save_settings(history_filename)


The file will be saved in Packages/User/YourPluginName.sublime-settings

EDIT: Using this method takes advantage of the code built into SublimeText to handle reading, writing and caching of the settings files. The settings are stored in a JSON formatted file.
Last edited by jbjornson on Wed Aug 31, 2011 9:31 am, edited 2 times in total.
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: Read and write custom settings file

Postby jbjornson on Wed Aug 31, 2011 9:27 am

jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: Read and write custom settings file

Postby jbrooksuk on Wed Aug 31, 2011 10:13 am

Perfect! Thank you :)

We could really do with examples of using the API functions, it would definitely help people like me.
jbrooksuk
 
Posts: 775
Joined: Sun Apr 11, 2010 10:37 am
Location: England


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 3 guests