Sublime Text Multiple Command Shortcut

pluginOn my team at work, many of us use the Sublime Text editor. I use two packages to keep my code clean – JsFormat and AmdButler. These are great, but it’s a pain to run them separately. Why not run them both with a single keyboard shortcut?! Here’s how to do that.

After you have both packages installed, go to “Tools > New Plugin”. Use this for your new plugin:

import sublime, sublime_plugin

class SortAndJsFormatCommand(sublime_plugin.TextCommand):
	def run(self, edit):
		self.view.run_command("amd_butler_sort")
		self.view.run_command("js_format")

Sublime Text automatically exposes a “command” by taking the camel-cased name of your python class, replaced with underscores, and removing the word “Command”. So the command name is “sort_and_js_format”. You can now use this if you go to “Preferences > Key Bindings – User” –

{"keys": ["ctrl+alt+s"], "command": "sort_and_js_format"}

(Thanks to this StackExchange answer for help)

Dojo Events – Template or Programmatic?

Events and how best to attach them to widgets.

When you are wiring up events in a custom, templated widget, do you wire them up using the template (using “data-dojo-attach-event”), or do you wire them up in the postCreate of your widget? Is one better than the other?

post-create-eventsvs.

template-version

Let me know in the comments!