forked from dopey/talon_user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
32 lines (28 loc) · 988 Bytes
/
code.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
from talon.voice import Context, Key
terminals = ('com.apple.Terminal', 'com.googlecode.iterm2')
ctx = Context('code', func=lambda app, win: any(
t in app.bundle for t in terminals))
#languages = ['.php', '.py', '.java', '.yml', '.json']
#bundles = ['com.postmanlabs.mac']
#ctx = Context('code', func=lambda app, win:
# any(app.bundle == b for b in bundles)
# or any(win.doc.endswith(l) for l in languages)
# )
def surround(by):
def func(i, word, last):
if i == 0:
word = by + word
if last:
word += by
return word
return func
keymap = {
'state if': ['if ()', Key('left')],
'state else': ['else {}', Key('left enter')],
'state else if': ['else if ()', Key('left')],
'state while': ['while ()', Key('left')],
'state for': ['for ()', Key('left')],
'state for each': ['foreach ()', Key('left')],
'state switch': ['switch ()', Key('left')],
}
ctx.keymap(keymap)