-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec_ruby_markers.py
31 lines (25 loc) · 1020 Bytes
/
exec_ruby_markers.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
import sublime, sublime_plugin, subprocess
class ExecuteAndUpdateRubyMarkers(sublime_plugin.TextCommand):
def run(self, edit):
r = sublime.Region(0, self.view.size())
text = self.view.substr(r)
settings = self.view.settings()
ruby_exec = '' if settings.get('ruby_exec') == None else '/usr/bin/ruby'
xmpfilter = '' if settings.get('xmpfilter') == None else '/usr/bin/xmpfilter'
s = subprocess.Popen(
[
'/usr/bin/env',
ruby_exec,
xmpfilter
],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out = s.communicate(text)
if s.returncode != None and s.returncode != 0:
sublime.message_dialog("There was an error: " + out[1])
return
viewlines = self.view.full_line(r)
outlines = out[0].split('\n')
self.view.erase(edit, r)
self.view.replace(edit, viewlines, out[0])