-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcompletion.py
More file actions
66 lines (51 loc) · 1.8 KB
/
completion.py
File metadata and controls
66 lines (51 loc) · 1.8 KB
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
import os
import time
import subprocess
from subprocess import Popen, PIPE
import sublime
import sublime_plugin
os_is_windows = os.name == 'nt'
chez_scheme_proc = None
def plugin_unloaded():
if scheme_is_in_place():
kill_process(chez_scheme_proc)
def scheme_is_in_place():
return chez_scheme_proc and chez_scheme_proc.poll() is None
# 如果你打开任务管理器并选中Sublime,然后关闭 sublime,
# 子进程不会被结束,而是在后台大量虚耗CPU
def kill_process(proc):
if os_is_windows:
killer = "TASKKILL /F /PID {pid} /T"
Popen(killer.format(pid=proc.pid), shell=True)
else:
os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
print("[Scheme.CodeHelper] terminated scheme process")
def check_scheme_process():
global chez_scheme_proc
if not scheme_is_in_place():
startupinfo = None
if os_is_windows:
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
proc = Popen("scheme", stdin=PIPE, stdout=PIPE, stderr=PIPE,
shell=True, startupinfo=startupinfo)
proc.stdout.read1(256)
chez_scheme_proc = proc
print("[Scheme.CodeHelper] created scheme process")
return chez_scheme_proc
class SchemeCodeHelperListener(sublime_plugin.EventListener):
view_environments = {}
def on_query_completions(self, view, prefix, locations):
"""(environment-symbols env-{view_view_id})
"""
pass
def on_load(self, view):
"""(define env-{view_view_id} (copy-environment (scheme-environment)))
"""
pass
def on_modified(self, view):
"""(eval {expr} env-{view.view_id})"""
pass
def on_close(self, view):
"""(set! env-{view_view_id} #f)"""
pass