Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
remove on_close hook
git view to run as parameter
move erase_status outside of loop
  • Loading branch information
unknownuser88 committed Feb 7, 2017
1 parent 7c0a44e commit 15c3497
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
hex2int
hex2int Preview
================

## Summary
Expand Down
34 changes: 14 additions & 20 deletions htoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,33 @@

class HtointCommand(sublime_plugin.EventListener):
def on_new(self, view):
self.view = view
self.run()

def on_close(self, view):
self.view.erase_status('Hexcode')
self.run(view)

def on_selection_modified(self, view):
self.view = view
self.run()
self.run(view)

def on_activated(self, view):
self.view = view
self.run()
self.run(view)

def run(self):
def run(self, view):
statusline = []
for region in self.view.sel():
for region in view.sel():

if region.begin() == region.end():
word = self.view.word(region)
word = view.word(region)
else:
word = region

if not word.empty():
keyword = self.view.substr(word)

keyword = view.substr(word)
isHex = re.findall(r'0x[0-9a-fA-F]+', keyword)
# print(isHex)

if isHex:
statusline.append('{} -> {}'.format(isHex[0], self.str_to_int(isHex[0])))
else:
self.view.erase_status('Hexcode')
else:
self.view.erase_status('Hexcode')
# print(", ".join(statusline))
self.view.set_status('Hexcode', '{}'.format(", ".join(statusline)))

view.erase_status('Hexcode')
view.set_status('Hexcode', '{}'.format(", ".join(statusline)))

def str_to_int(self, s):
i = int(s, 16)
Expand Down

0 comments on commit 15c3497

Please sign in to comment.