This repository has been archived by the owner on Apr 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
textmate.py
74 lines (62 loc) · 2.1 KB
/
textmate.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
import os
import sys
from pysmell import idehelper
from pysmell import tags as tags_module
from pysmell import tm_dialog
from pysmell import pysmell_client
import asyncore
from datetime import datetime
#tm_support_path = os.environ['TM_SUPPORT_PATH'] + '/lib'
#if tm_support_path not in sys.path:
#sys.path.insert(0, tm_support_path)
def write(word):
sys.stdout.write(word)
def tags(projectDir):
args = ['pysmell', projectDir, '-o', os.path.join(projectDir, 'PYSMELLTAGS')]
sys.argv = args
tags_module.main()
write('PYSMELLTAGS created in %s' % projectDir)
TOOLTIP = 206
def main():
cur_file = os.environ.get("TM_FILEPATH")
line_no = int(os.environ.get("TM_LINE_NUMBER"))
cur_col = int(os.environ.get("TM_LINE_INDEX"))
result = _main(cur_file, line_no, cur_col)
end = datetime.now()
if result is not None:
sys.exit(result)
def _main(cur_file, line_no, cur_col):
start = datetime.now()
if not cur_file:
write('No filename - is the file saved?')
return TOOLTIP
source = sys.stdin.read()
line = source.splitlines()[line_no - 1]
index = idehelper.findBase(line, cur_col)
base = line[index:cur_col]
pysmellClient = pysmell_client.client(cur_file, source, line_no, cur_col, base)
asyncore.loop()
completions = pysmellClient.completions
end = datetime.now()
if not completions:
write('No completions found')
return TOOLTIP
if len(completions) == 1:
new_word = completions[0]['word']
write(new_word[len(base):])
elif len(completions) > 1:
dialogTuples = [
(
"%s - %s" % (comp.get('abbr', comp['word']), comp.get('menu', '')),
index)
for index, comp in enumerate(completions)
]
try:
compIndex = tm_dialog.menu(dialogTuples)
except Exception, e:
import traceback
write(traceback.format_exc(e))
return TOOLTIP
if compIndex is not None:
write(completions[compIndex]['word'][len(base):])
print '#Took', (end-start).microseconds / 1000.0