Skip to content

Commit

Permalink
initial population
Browse files Browse the repository at this point in the history
  • Loading branch information
Davis Clark committed Sep 1, 2011
0 parents commit bc24c44
Show file tree
Hide file tree
Showing 7 changed files with 1,123 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@

*.pyc
3 changes: 3 additions & 0 deletions Default (Linux).sublime-keymap
@@ -0,0 +1,3 @@
[
{ "keys": ["ctrl+alt+f"], "command": "js_format"}
]
3 changes: 3 additions & 0 deletions Default (OSX).sublime-keymap
@@ -0,0 +1,3 @@
[
{ "keys": ["ctrl+alt+f"], "command": "js_format"}
]
3 changes: 3 additions & 0 deletions Default (Windows).sublime-keymap
@@ -0,0 +1,3 @@
[
{ "keys": ["ctrl+alt+f"], "command": "js_format"}
]
3 changes: 3 additions & 0 deletions JsFormat.sublime-commands
@@ -0,0 +1,3 @@
[
{ "caption": "Format: Javascript", "command": "js_format" }
]
15 changes: 15 additions & 0 deletions js_formatter.py
@@ -0,0 +1,15 @@
import sublime, sublime_plugin, jsbeautifier

class JsFormatCommand(sublime_plugin.TextCommand):
def run(self, edit):
opts = jsbeautifier.default_options();
opts.indent_char = " "
opts.indent_size = 4
opts.max_preserve_newlines = 3
selection = self.view.sel()[0]
replaceRegion = selection if len(selection) > 0 else sublime.Region(0, self.view.size())
res = jsbeautifier.beautify(self.view.substr(replaceRegion), opts)
prePos = self.view.sel()[0]
self.view.replace(edit, replaceRegion, res)
self.view.show_at_center(prePos.begin())

0 comments on commit bc24c44

Please sign in to comment.