forked from SublimeText/PackageDev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsublime_inspect.py
More file actions
57 lines (42 loc) · 1.5 KB
/
Copy pathsublime_inspect.py
File metadata and controls
57 lines (42 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import sublime, sublime_plugin
import sublime_lib
import os
import json
class SublimeInspect(sublime_plugin.WindowCommand):
def on_done(self, s):
rep = Report(s)
rep.show()
def run(self):
self.window.show_input_panel("Search String:", '', self.on_done, None, None)
class Report(object):
def __init__(self, s):
self.s = s
def collect_info(self):
try:
atts = dir(eval(self.s, {"sublime": sublime, "sublime_plugin": sublime_plugin}))
except NameError, e:
atts = e
self.data = atts
def show(self):
self.collect_info()
v = sublime.active_window().new_file()
v.insert(v.begin_edit(), 0, '\n'.join(self.data))
v.set_scratch(True)
v.set_name("SublimeInspect - Report")
class OpenSublimeSessionCommand(sublime_plugin.WindowCommand):
def run(self):
session_file = os.path.join(sublime.packages_path(), "..", "Settings", "Session.sublime_session")
self.window.open_file(session_file)
def to_json_type(v):
""""Convert string value to proper JSON type.
"""
try:
if v.lower() in ("false", "true"):
v = (True if v.lower() == "true" else False)
elif v.isdigit():
v = int(v)
elif v.replace(".", "").isdigit():
v = float(v)
except AttributeError:
raise ValueError("Conversion to JSON failed for: %s" % v)
return v