Merge pull request #2 from the3rdhbtaylor/master
The Enhancements I mentioned in my "Issue". -- Commit Summary -- * Added Process entire file, and configuration settings * Cleaned up TODO comments * Added source.json scope to Linux and Windows keymaps * Added Main.sublime-menu to surface the settings files * Added Default.sublime-commands to add prettyjson to the Commant Palette
This commit is contained in:
commit
ab00db3628
|
@ -1,3 +1,13 @@
|
|||
[
|
||||
{ "keys": ["ctrl+alt+j"], "command": "prettyjson" }
|
||||
{
|
||||
"keys": ["ctrl+alt+j"],
|
||||
"command": "prettyjson",
|
||||
"context": [
|
||||
{
|
||||
"key": "selector",
|
||||
"operator": "equal",
|
||||
"operand": "source.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -1,3 +1,14 @@
|
|||
[
|
||||
{ "keys": ["super+ctrl+j"], "command": "prettyjson" }
|
||||
// Only use this for the "source.json" scope
|
||||
{
|
||||
"keys": ["super+ctrl+j"],
|
||||
"command": "prettyjson",
|
||||
"context": [
|
||||
{
|
||||
"key": "selector",
|
||||
"operator": "equal",
|
||||
"operand": "source.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -1,3 +1,13 @@
|
|||
[
|
||||
{ "keys": ["ctrl+alt+j"], "command": "prettyjson" }
|
||||
{
|
||||
"keys": ["ctrl+alt+j"],
|
||||
"command": "prettyjson",
|
||||
"context": [
|
||||
{
|
||||
"key": "selector",
|
||||
"operator": "equal",
|
||||
"operand": "source.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -0,0 +1,6 @@
|
|||
[
|
||||
{
|
||||
"caption": "Pretty JSON: Reformat (Pretty Print) JSON",
|
||||
"command": "prettyjson"
|
||||
}
|
||||
]
|
|
@ -0,0 +1,39 @@
|
|||
[
|
||||
{
|
||||
"caption": "Preferences",
|
||||
"mnemonic": "n",
|
||||
"id": "preferences",
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"caption": "Package Settings",
|
||||
"mnemonic": "P",
|
||||
"id": "package-settings",
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"caption": "Pretty JSON",
|
||||
"children":
|
||||
[
|
||||
{
|
||||
"command": "open_file", "args":
|
||||
{
|
||||
"file": "${packages}/Pretty JSON/Pretty JSON.sublime-settings"
|
||||
},
|
||||
"caption": "Settings – Default"
|
||||
},
|
||||
{
|
||||
"command": "open_file", "args":
|
||||
{
|
||||
"file": "${packages}/User/Pretty JSON.sublime-settings"
|
||||
},
|
||||
"caption": "Settings – User"
|
||||
},
|
||||
{ "caption": "-" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"use_entire_file_if_no_selection" : true,
|
||||
"indent_size" : 4,
|
||||
"sort_keys" : true
|
||||
}
|
|
@ -2,14 +2,21 @@ import sublime
|
|||
import sublime_plugin
|
||||
import json
|
||||
|
||||
s = sublime.load_settings("Pretty JSON.sublime-settings")
|
||||
|
||||
class PrettyjsonCommand(sublime_plugin.TextCommand):
|
||||
""" Pretty Print JSON
|
||||
"""
|
||||
def run(self, edit):
|
||||
for region in self.view.sel():
|
||||
selection = self.view.substr(region)
|
||||
|
||||
# If no selection, use the entire file as the selection
|
||||
if region.empty() and s.get("use_entire_file_if_no_selection"):
|
||||
selection = sublime.Region(0, self.view.size())
|
||||
else:
|
||||
selection = region
|
||||
|
||||
try:
|
||||
obj = json.loads(selection)
|
||||
self.view.replace(edit, region, json.dumps(obj, indent=4, ensure_ascii=False, sort_keys=True))
|
||||
obj = json.loads(self.view.substr(selection))
|
||||
self.view.replace(edit, selection, json.dumps(obj, indent=s.get("indent_size", 4), ensure_ascii=False, sort_keys=s.get("sort_keys", True)))
|
||||
except Exception, e:
|
||||
sublime.status_message(str(e))
|
||||
|
|
Loading…
Reference in New Issue