Sublime Forum

Confused about .sublime-settings files

#1

Hi,

I wanted to add some adjustable settings to my plugin. My plugin is named ‘GranularSubword’ and I tried a directory structure like this:

Library
___Application Support
______Sublime Text 3
_________Packages
____________GranularSubword
_______________GranularSubword.sublime-settings
_______________GranularSubword.py
_______________Default.sublime-keymap

I put this in the file ‘GranularSubword.sublime-settings’:

{
    "a": true,
    "b": false
}

Then inside GranularSubword.py I try this:

import sublime
settings = sublime.load_settings('GranularSubword')
print(settings.get('a))

But this prints None instead of True.

What am I doing wrong?

0 Likes

#2

You need to specify the entire name of the setting file, including the extension, e.g.:

import sublime
settings = sublime.load_settings('GranularSubword.sublime-settings')
print(settings.get('a))

As a side note, this code is unsafe in that it attempts to use the API immediately at load time, which will work if the plugin reloads while Sublime is already running but not when the plugin is initially loaded after a restart. From the API documentation:

At importing time, plugins may not call any API functions, with the exception of sublime.version(), sublime.platform(), sublime.architecture() and sublime.channel().

If a plugin defines a module level function plugin_loaded(), this will be called when the API is ready to use. Plugins may also define plugin_unloaded(), to get notified just before the plugin is unloaded.

0 Likes

#3

OK it worked! Thanks!

0 Likes