Sublime Forum

Settings.get(val,default) returns None regardless of default

#1

I’m coming across a bug. When Sublime starts up, the Corona Editor plugin tries to read values from its settings files, and provides default values. However regardless of the default values, during startup, the settings instance returns None for all keys tested. If I reload the plugin after Sublime is up and running the values are set correctly. Is this a bug with Sublime or is Corona Editor doing something odd?

The offending code looks like:

def __init__(self):
    _corona_utils.debug("CoronaLabs: __init__")
    global CoronaCompletions
    CoronaCompletions = self
    # Use fuzzy completions (essentially search for the characters in the target even if separated)
    self._use_fuzzy_completion = _corona_utils.GetSetting("corona_sdk_use_fuzzy_completion", default=True) # returns None during startup
    # Remove whitespace in completions to match some coding styles
    self._strip_white_space = _corona_utils.GetSetting("corona_sdk_completions_strip_white_space", default=False)  # returns None during startup

The get setting function is a simple wrapper:

def GetSetting(key,default=None):
  # repeated calls to load_settings return same object without further disk reads
  s = sublime.load_settings('Corona Editor.sublime-settings')
  return s.get(key, default)

Given the different behaviour depending on where Sublime is in its state implies to me somethings wrong with Sublime, but as the editor code isn’t mine I’m happy to blame it too

0 Likes

#2

If this is ST3, then it’s not unexpected. From the docs:

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.

May be worth filing a bug about this with the plugin maintainer (if it’s not you).

0 Likes

#3

Thanks for the info. That makes sense of what’s going on!

0 Likes