-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhex-int-converter.py
58 lines (47 loc) · 2.01 KB
/
hex-int-converter.py
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
58
import sublime
import sublime_plugin
# sublime text drops the Command tail, then converts CamelCase to underscore seperated
# HexIntConverterCommand becomes hex_int_converter
class HexIntConverterCommand(sublime_plugin.TextCommand):
def run(self, edit):
#Get current window
view = self.view.window()
#Get current cursor and expand to word sellection
view.run_command("expand_selection",{"to":"word"})
#Set selection to first selected only
sels = self.view.substr(self.view.word(self.view.sel()[0]))
#If begining of selection is 0x number must be hex
if sels[:2] == "0x":
#replace with int representation
self.view.replace(edit,self.view.sel()[0],str(int(sels, 0)))
else:
#replace with hex representation
self.view.replace(edit,self.view.sel()[0],hex(int(sels)))
class ConvertIntCommand(sublime_plugin.TextCommand):
def run(self, edit, scope_selector, **kwargs):
#Get current window
view = self.view.window()
#Get current cursor and expand to word sellection
view.run_command("expand_selection",{"to":"word"})
#Set selection to first selected only
sels = self.view.substr(self.view.line(self.view.sel()[0]))
#replace with hex representation
self.view.replace(edit,self.view.sel()[0],hex(int(sels)))
def is_visible(self, scope_selector, **kwargs):
if self.view.match_selector(self.view.sel()[0].begin(), scope_selector) and scope_selector:
return True
return False
class ConvertHexCommand(sublime_plugin.TextCommand):
def run(self, edit, scope_selector, **kwargs):
#Get current window
view = self.view.window()
#Get current cursor and expand to word sellection
view.run_command("expand_selection",{"to":"word"})
#Set selection to first selected only
sels = self.view.substr(self.view.word(self.view.sel()[0]))
#replace with int representation
self.view.replace(edit,self.view.sel()[0],str(int(sels, 0)))
def is_visible(self, scope_selector, **kwargs):
if self.view.match_selector(self.view.sel()[0].begin(), scope_selector) and scope_selector:
return True
return False