diff --git a/JsFormat.sublime-settings b/JsFormat.sublime-settings index 9c9f091..303ce0a 100644 --- a/JsFormat.sublime-settings +++ b/JsFormat.sublime-settings @@ -13,5 +13,8 @@ "break_chained_methods": false, // jsformat options - "format_on_save": false + "format_on_save": false, + "format_by_extension_syntax": "both", + "format_file_extension": ["js", "json"], + "format_file_syntax": ["javascript", "json"] } \ No newline at end of file diff --git a/README.md b/README.md index 89b1b7f..90f3d35 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,9 @@ In addition, the following settings are available in JsFormat/JsFormat.sublime-s * "unescape_strings": false, * "break_chained_methods": false* * "format_on_save": false +* "format_by_extension_syntax": "both" (both, extension, syntax) +* "format_file_extension": ["js", "json"] +* "format_file_syntax": ["javascript", "json"] I had temporary lapse of judgement a while back and merged a pull request that modified jsbeautifier. As a result, the functionality that was added from that pull request has been lost; ```"ensure_space_before_linestarters"``` is no longer supported. diff --git a/js_formatter.py b/js_formatter.py index dea9acf..d1f8924 100644 --- a/js_formatter.py +++ b/js_formatter.py @@ -50,13 +50,23 @@ def is_js_buffer(view): syntaxPath = vSettings.get('syntax') syntax = "" ext = "" - - if (fName != None): # file exists, pull syntax type from extension - ext = os.path.splitext(fName)[1][1:] - if(syntaxPath != None): - syntax = os.path.splitext(syntaxPath)[0].split('/')[-1].lower() - - return ext in ['js', 'json'] or "javascript" in syntax or "json" in syntax + syntaxOrExtension = s.get("format_by_extension_syntax") + syntaxList = s.get("format_file_syntax") + extensionList = s.get("format_file_extension") + result = False + + if (syntaxOrExtension in ['both', 'extension']): + if (fName != None): # file exists, pull syntax type from extension + ext = os.path.splitext(fName)[1][1:] + if (ext in extensionList): + result = True + if (syntaxOrExtension in ['both', 'syntax']): + if(syntaxPath != None): + syntax = os.path.splitext(syntaxPath)[0].split('/')[-1].lower() + if (syntax in syntaxList): + result = True; + + return result class PreSaveFormatListner(sublime_plugin.EventListener): """Event listener to run JsFormat during the presave event"""