Skip to content

Instantly share code, notes, and snippets.

@billymoon
Last active December 12, 2017 10:09
Show Gist options
  • Save billymoon/35abc47dc1407931015aefa793e42894 to your computer and use it in GitHub Desktop.
Save billymoon/35abc47dc1407931015aefa793e42894 to your computer and use it in GitHub Desktop.
Hack to have single command to swap semi and standard linting and formatting
import sublime
import sublime_plugin
STANDARD_SETTINGS_FILE = "StandardFormat.sublime-settings"
SEMI_STANDARD_SETTINGS_FILE = "SemiStandardFormat.sublime-settings"
def plugin_loaded():
global standardSettings
global semiStandardSettings
standardSettings = sublime.load_settings(STANDARD_SETTINGS_FILE)
semiStandardSettings = sublime.load_settings(SEMI_STANDARD_SETTINGS_FILE)
class ChainCommand(sublime_plugin.WindowCommand):
def run(self, commands):
window = self.window
for command in commands:
command_name = command[0]
command_args = command[1:]
window.run_command(command_name, *command_args)
class EnableStandardCommand(sublime_plugin.WindowCommand):
def run(self):
standardSettings.set('format_on_save', True)
semiStandardSettings.set('format_on_save', False)
sublime.save_settings(STANDARD_SETTINGS_FILE)
sublime.save_settings(SEMI_STANDARD_SETTINGS_FILE)
sublime.status_message("Format on save: standard")
# self.window.run_command(command_name, *command_args)
class EnableSemiStandardCommand(sublime_plugin.WindowCommand):
def run(self):
standardSettings.set('format_on_save', False)
semiStandardSettings.set('format_on_save', True)
sublime.save_settings(STANDARD_SETTINGS_FILE)
sublime.save_settings(SEMI_STANDARD_SETTINGS_FILE)
sublime.status_message("Format on save: semi-standard")
### Keymap entries
# { "keys": ["ctrl+alt+super+'"], "command": "chain", "args": {"commands":[
# ["sublimelinter_toggle_linter", {"enable": "standard"}],
# ["sublimelinter_toggle_linter", {"disable": "semistandard"}],
# ["enable_standard"],
# ["standard_format"]
# ]}},
# { "keys": ["ctrl+alt+super+;"], "command": "chain", "args": {"commands":[
# ["sublimelinter_toggle_linter", {"enable": "semistandard"}],
# ["sublimelinter_toggle_linter", {"disable": "standard"}],
# ["enable_semi_standard"],
# ["semi_standard_format"]
# ]}},
### Handle enable/disable in SublimeLinter
# --- /Users/billymoon/Library/Application Support/Sublime Text 3/Packages/SublimeLinter/commands.py
# +++ (clipboard)
# @@ -765,10 +765,26 @@
# return len(self.linters[which]) > 0
# def run(self, **args):
# +
# """Run the command."""
# - self.which = args['which']
# -
# - if self.linters[self.which]:
# + if 'which' in args:
# + self.which = args['which']
# +
# + # TODO: commit this somewhere
# + if 'disable' in args:
# + settings = persist.settings.get('linters', {})
# + linter_settings = settings.get(args['disable'], {})
# + linter_settings['@disable'] = True
# + persist.settings.set('linters', settings, changed=True)
# + persist.settings.save()
# + elif 'enable' in args:
# + settings = persist.settings.get('linters', {})
# + linter_settings = settings.get(args['enable'], {})
# + linter_settings['@disable'] = False
# + persist.settings.set('linters', settings, changed=True)
# + persist.settings.save()
# + elif self.linters[self.which]:
# + print(2, args['which'], self.linters[self.which])
# self.window.show_quick_panel(self.linters[self.which], self.on_done)
# def on_done(self, index):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment