forked from dopey/talon_user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvim.py
218 lines (183 loc) · 4.62 KB
/
vim.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
from talon.voice import Context, Str, Word, Key, Rep, press
from typing import Iterable
import functools
import time
ctx = Context('vim', bundle='com.googlecode.iterm2')
def prefix(destination, item):
if isinstance(destination, Iterable):
result = [item]
result.extend(destination)
return result
else:
return [item, destination]
def temp_escape_prefix(command):
# ',' is my leader key in vim
# ',/': maps to '<esc>l' in insert mode, maps to '<nop>' in other modes.
return prefix(command, ',/')
def get_first_word(input):
print(input.dgndictation[0]._words)
return str(input.dgndictation[0]._words[0]).lower()
def find_next_word(input):
word = get_first_word(input)
Str("/%s\n" % word)(None)
numeral_map = {
'o': '0',
'oh': '0',
'gun': '1',
'shoe': '2',
'me': '3',
'door': '4',
'dive': '5',
'sticks': '6',
'heaven': '7',
'gate': '8',
'knife': '9',
'nice': '9'
}
delimiter_words = ['click', 'clip']
def parse_first_number(words):
result = ''
for index, word in enumerate(words):
if word in delimiter_words:
return (result, words[index+1:])
if not word in numeral_map:
raise Exception('%s not a number' % word)
result += numeral_map[word]
return (result, [])
def parse_word(word):
word = word.lstrip('\\').split('\\', 1)[0]
return word
def get_words(input):
tmp = [str(s).lower() for s in input.dgndictation[0]._words]
words = [parse_word(word) for word in tmp]
return words
def jump(input):
words = get_words(input)
jump_first(words)
def jump_first(words):
line, remainder = parse_first_number(words)
if line != '':
Str("%sgg" % line)(None)
return remainder
def range_action(action, input):
words = get_words(input)
print(words)
remainder = jump_first(words)
press('V')
if remainder:
jump_first(remainder)
press(action)
for_temp_escape_prefix = {
# range-copy
'yank <dgndictation>': functools.partial(range_action, 'y'),
# range-delete
'delete lines <dgndictation>': functools.partial(range_action, 'd'),
# range-poach
'poach <dgndictation>': functools.partial(range_action, 'p'),
# range-visual
'visor <dgndictation>': functools.partial(range_action, ''),
# jump
'spring <dgndictation>': jump,
# move-back-big-word
'basil': 'B',
# move-back-big-word-insert
'basey': 'Bi',
# move-back-word
'baz': 'b',
# move-back-word-insert
'bazy': 'bi',
# move-bottom
'doomway': 'G',
# move-forward-word
'wax': 'w',
# move-forward-word
'waxy': 'wi',
# move-forward-big-word
'wacko': 'W',
# move-forward-big-word-insert
'wacky': 'Wi',
# move-line-end-insert
'derek': 'A',
# move-page-down
'page down': Key('ctrl-d'),
# move-page-up
'page up': Key('ctrl-u'),
# move-top
'goofy': 'gg',
# surround-change
'chapel': 'cs',
# surround-delete
'delltrap': 'ds',
# surround-word
'trap': 'ysiw',
# surround-word-big
'traple': 'ysiW',
# redo
'rizzle': Key('ctr-r'),
# undo
'dizzle': 'u',
# fugitive-add
'fudge pack': ':Gwrite\n',
# fugitive-commit
'fudge commit': [':Gcommit -v -a -q\n', 'i'],
# fugitive-push
'fudge push': ':Gpush origin HEAD\n',
# fugitive-status
'fudge status': ':Gstatus\n',
# combine-line
'jiggle': 'J',
# new-line-above
'spronko': 'O',
# new-line-below
'spronk': 'o',
# find
'marco': '/',
# find-current
'marthis': '*',
# find-dictation
'crew <dgndictation>': find_next_word,
# find-next
'marneck': 'n',
# find-next
'marprev': 'N',
# repeat
'rep': Rep(1),
# center
'zen': 'zz',
# execute to the right
'slap': [':w\n', lambda m: time.sleep(0.50), Key('cmd-right up enter')],
# cut line
'chomp': 'cc',
# buffer-quit
'barf': ':q\n',
# buffer-write
'sage': ':w\n',
# buffer-write-quit
'ragequit': ':wq\n',
# escape
'lulu': Key('right'),
}
keymap = {
# copy
'yank': 'yy',
# delete
'delete line': 'dd',
# delete-partial-word
'dick': 'de',
# delete-partial-big-word
'dickle': 'dE',
# jump
'jump': 'gg',
# jump-insert-bol
'jumpy': 'ggi',
# jump-insert-eol
'jumper': 'ggA',
# jump-new-below
'jumpo': 'ggo',
# symbol
'kirblock': ['{\n}', Key('esc'), lambda m: time.sleep(0.1), 'O'],
# buffer-write-build
'combat': ',b',
}
keymap.update({k: temp_escape_prefix(for_temp_escape_prefix[k]) for k in for_temp_escape_prefix})
ctx.keymap(keymap)