Permalink
Browse files

Merge pull request #13 from bizoo/master

Update jsbeautifier to last version
  • Loading branch information...
2 parents 1205031 + 2d51aa6 commit 0a7fbff383270da24cec0cfafc5d34e1e6070912 @jdc0589 committed Mar 14, 2012
Showing with 143 additions and 80 deletions.
  1. +3 −2 JsFormat.sublime-settings
  2. +2 −1 README.md
  3. +10 −9 js_formatter.py
  4. +128 −68 jsbeautifier.py
@@ -1,8 +1,9 @@
{
"brace_style": "collapse",
- "indent_level": 0,
"jslint_happy": false,
"keep_array_indentation": false,
"max_preserve_newlines": 4,
- "preserve_newlines": true
+ "preserve_newlines": true,
+ "keep_function_indentation": false,
+ "indent_with_tabs": false
}
View
@@ -21,7 +21,8 @@ In addition, the following settings are available in JsFormat/JsFormat.sublime-s
* "jslint_happy": false
* "brace_style": "collapse"
* "keep_array_indentation": false
-* "indent_level": 0
+* "keep_function_indentation": false
+* "indent_with_tabs": false
## Install
#### [Package Control](https://github.com/wbond/sublime_package_control) (*Recommended*)
View
@@ -9,16 +9,17 @@ def run(self, edit):
# settings
opts = jsbeautifier.default_options()
opts.indent_char = " " if settings.get("translate_tabs_to_spaces") else "\t"
- opts.indent_size = int(settings.get("tab_size")) if opts.indent_char == " " else 1
+ opts.indent_size = int(settings.get("tab_size")) if opts.indent_char == " " else 1
opts.max_preserve_newlines = s.get("max_preserve_newlines") or 3
opts.preserve_newlines = s.get("preserve_newlines") or True
opts.jslint_happy = s.get("jslint_happy") or False
opts.brace_style = s.get("brace_style") or "collapse"
- opts.s = s.get("keep_array_indentation") or False
- opts.indent_level = s.get("indent_level") or 0
+ opts.keep_array_indentation = s.get("keep_array_indentation") or False
+ opts.keep_function_indentation = s.get("keep_function_indentation") or False
+ opts.indent_with_tabs = s.get("indent_with_tabs") or False
selection = self.view.sel()[0]
- nwsOffset = self.prev_non_whitespace()
+ nwsOffset = self.prev_non_whitespace()
# do formatting and replacement
replaceRegion = None
@@ -27,12 +28,12 @@ def run(self, edit):
# formatting a selection/highlighted area
if(len(selection) > 0):
formatSelection = True
- replaceRegion = selection
+ replaceRegion = selection
- # formatting the entire file
- else:
+ # formatting the entire file
+ else:
replaceRegion = sublime.Region(0, self.view.size())
-
+
res = jsbeautifier.beautify(self.view.substr(replaceRegion), opts)
if(not formatSelection):
res = res + "\n"
@@ -62,7 +63,7 @@ def get_nws_offset(self, nonWsChars, buff):
offset += 1
if not(buff[i].isspace()):
nonWsSeen += 1
-
+
if(nonWsSeen == nonWsChars):
break
Oops, something went wrong.

0 comments on commit 0a7fbff

Please sign in to comment.