-
Notifications
You must be signed in to change notification settings - Fork 1
/
igor.py
58 lines (44 loc) · 1.77 KB
/
igor.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
import subprocess
import sublime
import sublime_plugin
from local_settings import COMMAND
class IgorReaperCommand(sublime_plugin.EventListener):
"""On save of Python files, reap for mr.igor
"""
def on_post_save(self, view):
if not 'python' in view.settings().get('syntax').lower():
return
filename = view.file_name()
igor_cmd = '%s --reap "%s"' % (COMMAND, filename,)
out = subprocess.Popen(igor_cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()
if out[1]:
sublime.error_message(out[1].decode('utf-8'))
else:
sublime.status_message("Reaped")
class IgorReplaceCommand(sublime_plugin.TextCommand):
"""Replace the contents of the current buffer with the outputs
of mr.igor
"""
def run(self, edit):
if not 'python' in self.view.settings().get('syntax').lower():
return
filename = self.view.file_name()
igor_cmd = '%s --print "%s"' % (COMMAND, filename,)
self.view.run_command('save')
out = subprocess.Popen(igor_cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()
if out[1]:
sublime.error_message(out[1].decode('utf-8'))
else:
if out[0]:
out = ''.join(out[0])
out = out.replace('%s:' % filename, '')
replacement = out.strip()
region = sublime.Region(0, self.view.size())
self.view.replace(edit, region, replacement)
sublime.status_message("Updated")