diff --git a/Pretty JSON.sublime-settings b/Pretty JSON.sublime-settings index 7c5e659..e688f53 100644 --- a/Pretty JSON.sublime-settings +++ b/Pretty JSON.sublime-settings @@ -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 } \ No newline at end of file diff --git a/PrettyJsonListeners.py b/PrettyJsonListeners.py index 4c7d391..a3d91e0 100644 --- a/PrettyJsonListeners.py +++ b/PrettyJsonListeners.py @@ -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() \ No newline at end of file + 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') diff --git a/README.md b/README.md index d43ada2..2ecba6d 100644 --- a/README.md +++ b/README.md @@ -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