Sublime Forum

Read and write custom settings file

#1

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

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.

0 Likes

#2

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

    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.

0 Likes

#3

Check out the settings API for more options: http://www.sublimetext.com/docs/2/api_reference.html#sublime.Settings

0 Likes

#4

Perfect! Thank you :smile:

We could really do with examples of using the API functions, it would definitely help people like me.

0 Likes