Sublime Forum

Package specific - key binding - change setting

#1

Does anyone know how to set a key binding that alters a package specific setting?

I have had success changing Sublime Text settings using the following:

{ "keys": "ctrl+alt+space"], "command": "set_setting", "args": { "setting": "highlight_line", "value": "true", } },

but have been unsuccessful in changing package specific settings by using similar conventions.

I have tried:

{ "keys": "ctrl+alt+space"], "command": "set_setting", "args": { "setting": "bh_core.sublimesettings/high_visibility_style", "value": "solid", } },

And also the following variations:

"setting": "high_visibility_style", "setting": "bh_core/high_visibility_style", "setting": "bh_core.sublimesettings/high_visibility_style", "setting": "packages/user/bh_core.sublimesettings/high_visibility_style",

0 Likes

#2

I believe you will need to either use a built in command for the plugin, or implement your own solution to toggle settings for a plugin. I believe brackethighlighter uses set_key to assign setting values. If you wanted to roll your own solution to toggle mutliple plugins you would need to know the package setting file name, the key, and the value you want to assign. Something like this would work for simple settings, but arrays and dicts will need more work:

import sublime, sublime_plugin

class CustomSetSettingCommand(sublime_plugin.ApplicationCommand):
    def run(self, file, key, value):
        settings = sublime.load_settings(file)
        settings.set(key, value)
        sublime.save_settings(file)

Then just create your keybindings like such:


	{"keys": "ctrl+alt+1"], "command": "custom_set_setting", "args": {"file": "bh_core.sublime-settings",  "key": "high_visibility_style", "value": "solid"}},
	{"keys": "ctrl+alt+2"], "command": "custom_set_setting", "args": {"file": "bh_core.sublime-settings",  "key": "high_visibility_style", "value": "outline"}}
]

I would recommend using the plugins method if there is one as any changes that are made to the plugin will not break your keybindings (most likely!).

0 Likes

#3

[quote=“huot25”]

import sublime, sublime_plugin

class CustomSetSettingCommand(sublime_plugin.ApplicationCommand):
    def run(self, file, key, value):
        settings = sublime.load_settings(file)
        settings.set(key, value)
        sublime.save_settings(file)

Nice! BracketHighlighter does not offer the ability to toggle highlight style, it can only be changed via the settings file.
So I will definitely give your method a shot.

I understand the keybind part, but where would I put the “CustomSetSettingCommand” code?

Also, from looking at your 2 code snippets I would guess that if you create a command like “WordoneWordtwoWordthreeCommand”
that it is interpreted @ the point of keybinding as “Wordone_Wordtwo_Wordthree”, and that the snakecase variant of the command name should be enclosed in quotes & preceded by “command”:

Is that accurate?[/quote]

0 Likes