forked from anonfunc/talon-user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
language.py
54 lines (50 loc) · 1.61 KB
/
language.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
from talon.voice import Context, Key
def ExtensionContext(ext):
def language_match(app, win):
title = win.title
#print("Window title:" + title)
if app.bundle == 'com.microsoft.VSCode':
if u'\u2014' in title:
filename = title.split(u' \u2014 ', 1)[0] # Unicode em dash!
elif '-' in title:
filename = title.split(u' - ', 1)[0]
elif app.bundle == 'com.apple.Terminal':
parts = title.split(' \u2014 ')
if len(parts) >= 2 and parts[1].startswith(('vi ', 'vim ')):
filename = parts[1].split(' ', 1)[1]
else: return False
elif win.doc:
filename = win.doc
else: return False
filename = filename.strip()
return filename.endswith(ext)
return language_match
ctx = Context('python', func=ExtensionContext('.py'))
# ctx.vocab = [
# '',
# '',
# ]
# ctx.vocab_remove = ['']
ctx.keymap({
'state (def | deaf | deft)': 'def ',
'state else if': 'elif ',
'state if': 'if ',
'state else if': [' else if ()', Key('left')],
'state while': ['while ()', Key('left')],
'state for': 'for ',
'state import': 'import ',
'state class': 'class ',
'state (past | pass)': 'pass',
})
ctx = Context('golang', func=ExtensionContext('.go'))
ctx.keymap({
'state (funk | func | fun)': 'func ',
'state if': 'if ',
'state else if': ' else if ',
'state while': 'for ',
'state for': 'for ',
'state switch': 'switch ',
'state case': 'case ',
'state type': 'type ',
'state (start | struct | struck)': 'struct ',
})