-
Notifications
You must be signed in to change notification settings - Fork 5
/
oz_plugin.py
118 lines (94 loc) · 2.5 KB
/
oz_plugin.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import subprocess
from subprocess import PIPE, Popen
import sublime
import sublime_plugin
import threading
from .socket_pipe import OzThread
sp = None
def with_oz(f):
def wrapper(*args, **kwargs):
global sp
if not sp:
start_oz()
f(*args, **kwargs)
return wrapper
def start_oz():
global sp
sp = OzThread()
sp.start()
class OzRunCommand(sublime_plugin.TextCommand):
@with_oz
def run(self, edit):
pass
@with_oz
def feed_region(view):
global sp
msg = ""
for region in view.sel():
if not region.empty():
msg += view.substr(region)
sp.send(msg)
class OzFeedRegion(sublime_plugin.TextCommand):
def run(self, edit):
feed_region(self.view)
def is_enabled(self):
for region in self.view.sel():
if not region.empty():
return True
return False
def description(self):
"Feed the selected text to the Oz compiler"
@with_oz
def feed_line(view):
global sp
msg = ""
for region in view.sel():
if region.empty:
line = view.line(region)
msg += view.substr(line) + '\n'
sp.send(msg)
class OzFeedLine(sublime_plugin.TextCommand):
def run(self, edit):
feed_line(self.view)
def is_enabled(self):
for region in self.view.sel():
if region.empty():
return True
return False
def description(self):
"Feed the current line to the Oz compiler"
class OzFeedBuffer(sublime_plugin.TextCommand):
@with_oz
def run(self, edit):
global sp
msg = self.view.substr(sublime.Region(0, self.view.size()))
sp.send(msg)
def description(self):
"Feed the current file to the Oz compiler"
class OzFeedContext(sublime_plugin.TextCommand):
def run(self, edit):
global sp
msg = ""
for region in self.view.sel():
if not region.empty:
return feed_region(self.view)
return feed_line(self.view)
def is_enabled(self):
for region in self.view.sel():
return True
return False
def description(self):
"Feed text to the Oz compiler"
def stop():
global sp
if sp:
sp.stop()
sp = None
class OzKillCommand(sublime_plugin.TextCommand):
def run(self, edit):
stop()
def description(self):
"Kill the Oz compiler"
class ExitListener(sublime_plugin.EventListener):
def on_pre_close(view):
stop()