Permalink
Browse files

add format on save control feature

  • Loading branch information...
1 parent 8460072 commit 7dee297869ac5cc825174a3347d0ea475fff57eb @jdc0589 committed Oct 14, 2015
Showing with 8 additions and 8 deletions.
  1. +1 −4 JsFormat.sublime-settings
  2. +4 −3 README.md
  3. +3 −1 js_formatter.py
@@ -19,8 +19,5 @@
"format_selection": true,
"jsbeautifyrc_files": false,
"ignore_sublime_settings": true,
-
- // On Save File Filter
- // Please use regular expression
- "format_on_save_filter": "\\.(js|jason)$"
+ "format_on_save_extensions": ["js", "json"]
}
View
@@ -36,6 +36,7 @@ The following **JsBeautifier** settings are available in JsFormat/JsFormat.subli
The following **JsFormat** specific settings are also exposed:
- `format_on_save`: false (format files on buffer save)
+- `format_on_save_extensions`: ["js", "json"] (extensions of files that will be formatted on save)
- `jsbeautifyrc_files`: false (see the [.jsbeautifyrc files](#jsbeautifyrc-files) section)
I had temporary lapse of judgment a while back and merged a pull request that modified jsbeautifier. As a result, the functionality that
@@ -44,14 +45,14 @@ was added from that pull request has been lost; ```"ensure_space_before_linestar
The JsFormat specific ```ensure_newline_at_eof_on_save``` setting has also been removed. This functionality exists in sublime core.
#### jsbeautifyrc files ####
-JsFormat now supports `.jsbeautifyrc` JSON files (disabled by default), which themselves support any of the exposed JsBeautifier options. The option augmentation order is: default options -> user settings -> `.jsbeautifyrc` option files.
+JsFormat now supports `.jsbeautifyrc` JSON files (disabled by default), which themselves support any of the exposed JsBeautifier options. The option augmentation order is: default options -> user settings -> `.jsbeautifyrc` option files.
-A hierarchy of `.jsbeautifyrc` files is supported, where rc files at the deeper levels override the settings from rc files at higher levels. For example, given the file structure listed below, formatting `/home/you/myProject/app.js` would inherit settings from: default -> user settings -> `/home/you/myProject/.jsbeautifyrc`, while formatting `/home/you/myProject/tests/test.js` would inherit settings from: default -> user settings -> `/home/you/myProject/.jsbeautifyrc` -> `/home/you/myProject/tests/.jsbeautifyrc`
+A hierarchy of `.jsbeautifyrc` files is supported, where rc files at the deeper levels override the settings from rc files at higher levels. For example, given the file structure listed below, formatting `/home/you/myProject/app.js` would inherit settings from: default -> user settings -> `/home/you/myProject/.jsbeautifyrc`, while formatting `/home/you/myProject/tests/test.js` would inherit settings from: default -> user settings -> `/home/you/myProject/.jsbeautifyrc` -> `/home/you/myProject/tests/.jsbeautifyrc`
- /home/you/myProject/.jsbeautifyrc
- /home/you/myProject/app.js
- /home/you/myProject/tests/.jsbeautifyrc
-- /home/you/myProject/tests/test.js
+- /home/you/myProject/tests/test.js
View
@@ -61,7 +61,9 @@ class PreSaveFormatListner(sublime_plugin.EventListener):
"""Event listener to run JsFormat during the presave event"""
def on_pre_save(self, view):
- if(s.get("format_on_save") and re.search(s.get("format_on_save_filter"), view.file_name())):
+ extOrClause = "|".join(s.get("format_on_save_extensions"))
+ extRegex = "\\.(" + extOrClause + ")$"
+ if(s.get("format_on_save") and re.search(extRegex, view.file_name())):
# only auto-format on save if there are no "lint errors"
# here are some named regions from sublimelint see https://github.com/lunixbochs/sublimelint/tree/st3
lints_regions = ['lint-keyword-underline', 'lint-keyword-outline']

0 comments on commit 7dee297

Please sign in to comment.