Last active
April 15, 2016 14:08
-
-
Save jeremywen/63cbc2b2e6b48bc70bf2e28a370c9f1c to your computer and use it in GitHub Desktop.
Sublime Text 3 plugins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin, os.path | |
############################################################################################ | |
# Copy this file to: | |
# ~/Library/Application Support/Sublime Text 3/Packages/User/JW-QuickTools.py | |
############################################################################################ | |
############################################################################################ | |
# LogVarsCommand: | |
# This command will insert log statements for each selected variable. | |
# Example: | |
# if these two string where selected and the file extension is .js -> | |
# ... teststring1 ... | |
# ... teststring2 ... | |
# then two log statements would be inserted above them -> | |
# console.log("teststring1="+teststring1); | |
# ... teststring1 ... | |
# console.log("teststring2="+teststring2); | |
# ... teststring2 ... | |
# | |
# To use this command, add a mapping like this to the user keymap: | |
# { "keys": ["super+shift+l"], "command": "log_vars" } | |
############################################################################################ | |
class LogVarsCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
selection = self.view.sel() | |
for region in selection: | |
regionTxt = self.view.substr(region) | |
line = self.view.line(region) | |
fileExt = self.view.window().extract_variables()['file_extension'] | |
methodMap = {"js":"console.log", "py":"print", "java":"log.debug", "groovy":"log.debug"} | |
lineEnd = {"js":";", "py":"", "java":";", "groovy":""} | |
lineContents = methodMap[fileExt] + "(\"" + regionTxt + "=\" + " + regionTxt + ")" + lineEnd[fileExt] + "\n" | |
self.view.insert(edit, line.begin(), lineContents) | |
############################################################################################ | |
# EmberJumpCommand: | |
# This command will jump between component hbs and js files. | |
# To use this command, add a mapping like this to the user keymap: | |
# { "keys": ["super+shift+j"], "command": "ember_jump" } | |
############################################################################################ | |
class EmberJumpCommand(sublime_plugin.WindowCommand): | |
def run(self): | |
var_map = self.window.extract_variables() | |
file = var_map['file'] | |
file_path = var_map['file_path'] | |
if '/app/components' in file_path: | |
template = file.replace('/components', '/templates/components').replace('.js', '.hbs') | |
self.window.open_file(template) | |
self.window.focus_view(self.window.find_open_file(template)) | |
elif '/app/templates' in file_path: | |
component = file.replace('/templates', '').replace('.hbs', '.js') | |
self.window.open_file(component) | |
self.window.focus_view(self.window.find_open_file(component)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment