Hello all! I am here yet again with another nifty & time-saving utility for use in all your wonderful plugins.
This time I would like to present an expressive and easy way to load settings through the use of declarative structures and class attributes - the SublimeDeclarativeSettings plugin.
With this plugin, all you have to do is have your commands declare the setting keys, attributes to bind to, and the default values, and the loader will take care of loading and updating the values:
from DeclarativeSublimeSettings import DeclarativeSettingsMixin
class WordFinder(DeclarativeSettingsMixin, ApplicationCommand):
setting_entries = (
('enabled', 'word_finder.enabled', True)
)
def __init__(self):
self.load_settings("word_finder.sublime-settings")
def run(*args, **kwargs):
print(self.enabled)
This is a very useful solution if you have a lot of command-specific settings, and the declarative approach means you don’t have to worry about loading and reloading the settings. There are a couple other features, such as embedding/reusing other setting trees, and extending how entries are processed. A full outline can be found at the repository.
I’ve currently submitted a pull request to the main Package-Control repository so that this can be added as a dependency.