#40 pretty_on_save config to enable pretty on save

This commit is contained in:
Nikolajus 2016-07-15 17:39:50 +02:00
parent 62bdb1d281
commit 7b7ca7b4c1
3 changed files with 15 additions and 2 deletions

View File

@ -6,5 +6,6 @@
"line_separator": ",",
"value_separator": ": ",
"keep_arrays_single_line": false,
"max_arrays_line_length": 120
"max_arrays_line_length": 120,
"pretty_on_save": false
}

View File

@ -7,6 +7,8 @@ try:
except ValueError:
from PrettyJson import PrettyJsonBaseCommand
s = sublime.load_settings("Pretty JSON.sublime-settings")
class PrettyJsonLintListener(sublime_plugin.EventListener, PrettyJsonBaseCommand):
def on_post_save(self, view):
@ -22,4 +24,11 @@ class PrettyJsonLintListener(sublime_plugin.EventListener, PrettyJsonBaseCommand
try:
self.json_loads(json_content)
except Exception:
self.show_exception()
self.show_exception()
class PrettyJsonAutoPrettyOnSaveListener(sublime_plugin.EventListener):
def on_pre_save(self, edit):
auto_pretty = s.get("pretty_on_save", False)
if auto_pretty:
sublime.active_window().run_command('pretty_json')

View File

@ -77,6 +77,9 @@ http://stedolan.github.io/jq/
**max_arrays_line_length** - 120
`if array for example '["a", "b", 123213, ....]' length will reach max it will be kept multi-line (for beauty)`
**pretty_on_save** - false
`do we need to automatically Pretty JSON on save`
## Using tabs for indentation
You can change configuration key **indent** to string value "\t" or any other string