Sources/OrgCore/Keymap/PresetDoom.swift
546 lines · 15576 bytes
1extension KeymapPreset {
2 static var doomToml: String {
3 var problems: [String] = []
4 let emacs = try! Keymap(toml: common + emacsBindings, problems: &problems)
5 let translations: [String: String] = ["<left>": "h", "<right>": "l", "<up>": "k", "<down>": "j"]
6 var out = ""
7 func bind(_ keys: String, _ command: String, when: String?, mode: String) {
8 out += "[[bind]]\nkeys = \"\(keys.replacingOccurrences(of: "\\", with: "\\\\"))\"\ncommand = \"\(command)\"\n"
9 if let when { out += "when = \"\(when)\"\n" }
10 out += "mode = \"\(mode)\"\n"
11 }
12 for binding in emacs.bindings {
13 let first = binding.keys[0]
14 let keys = KeySequence.format(binding.keys)
15 let orgKey = first.key == "c" && first.modifiers == [.control] || first.key == "x" && first.modifiers == [.control]
16 || (first.modifiers.contains(.meta) && ["<left>", "<right>", "<up>", "<down>", "RET"].contains(first.key))
17 || (first.modifiers.contains(.shift) && ["<left>", "<right>", "<up>", "<down>"].contains(first.key))
18 || (first.modifiers == [.control] && first.key == "RET")
19 || keys == "M-x" || keys == "M-q"
20 guard orgKey else { continue }
21 for mode in ["normal", "insert", "visual"] { bind(keys, binding.command, when: binding.when, mode: mode) }
22 // evil-org: M-h/j/k/l and M-H/J/K/L in normal, visual and insert.
23 if binding.keys.count == 1, first.modifiers.contains(.meta), let letter = translations[first.key] {
24 let shifted = first.modifiers.contains(.shift)
25 let key = "M-" + (shifted ? letter.uppercased() : letter)
26 for mode in ["normal", "insert", "visual"] { bind(key, binding.command, when: binding.when, mode: mode) }
27 }
28 // Doom: C-S-h/j/k/l are org-shift* in normal and insert.
29 if binding.keys.count == 1, first.modifiers == [.shift], let letter = translations[first.key] {
30 for mode in ["normal", "insert"] { bind("C-" + letter.uppercased(), binding.command, when: binding.when, mode: mode) }
31 }
32 // evil-org insert state: C-t demotes, C-d promotes.
33 if binding.keys.count == 1, first.modifiers == [.meta], first.key == "<right>" || first.key == "<left>" {
34 bind(first.key == "<right>" ? "C-t" : "C-d", binding.command, when: binding.when, mode: "insert")
35 }
36 }
37 return out + doomBindings
38 }
39
40 static let doomBindings = """
41 # Leader
42 [[bind]]
43 keys = "SPC SPC"
44 command = "app.quick-open"
45 mode = "normal"
46 [[bind]]
47 keys = "SPC q q"
48 command = "app.quit"
49 mode = "normal"
50 [[bind]]
51 keys = "SPC ."
52 command = "app.quick-open"
53 mode = "normal"
54 [[bind]]
55 keys = "SPC f f"
56 command = "app.quick-open"
57 mode = "normal"
58 [[bind]]
59 keys = "SPC f s"
60 command = "app.save"
61 mode = "normal"
62 # Windows
63 [[bind]]
64 keys = "SPC w s"
65 command = "app.split-below"
66 mode = "normal"
67 [[bind]]
68 keys = "SPC w v"
69 command = "app.split-right"
70 mode = "normal"
71 [[bind]]
72 keys = "SPC w d"
73 command = "app.pane-close"
74 mode = "normal"
75 [[bind]]
76 keys = "SPC w c"
77 command = "app.pane-close"
78 mode = "normal"
79 [[bind]]
80 keys = "SPC w o"
81 command = "app.pane-only"
82 mode = "normal"
83 [[bind]]
84 keys = "SPC w w"
85 command = "app.pane-next"
86 mode = "normal"
87 [[bind]]
88 keys = "SPC w n"
89 command = "app.window-new"
90 mode = "normal"
91 [[bind]]
92 keys = "C-w s"
93 command = "app.split-below"
94 mode = "normal"
95 [[bind]]
96 keys = "C-w v"
97 command = "app.split-right"
98 mode = "normal"
99 [[bind]]
100 keys = "C-w c"
101 command = "app.pane-close"
102 mode = "normal"
103 [[bind]]
104 keys = "C-w o"
105 command = "app.pane-only"
106 mode = "normal"
107 [[bind]]
108 keys = "C-w w"
109 command = "app.pane-next"
110 mode = "normal"
111 # Buffers
112 [[bind]]
113 keys = "SPC b b"
114 command = "app.buffer.switch"
115 mode = "normal"
116 [[bind]]
117 keys = "SPC b B"
118 command = "app.buffer.switch"
119 mode = "normal"
120 [[bind]]
121 keys = "SPC ,"
122 command = "app.buffer.switch"
123 mode = "normal"
124 [[bind]]
125 keys = "SPC `"
126 command = "app.buffer.last"
127 mode = "normal"
128 [[bind]]
129 keys = "SPC b k"
130 command = "app.buffer.kill"
131 mode = "normal"
132 [[bind]]
133 keys = "SPC b d"
134 command = "app.buffer.kill"
135 mode = "normal"
136 [[bind]]
137 keys = "SPC b K"
138 command = "app.buffer.kill-all"
139 mode = "normal"
140 [[bind]]
141 keys = "SPC b O"
142 command = "app.buffer.kill-others"
143 mode = "normal"
144 [[bind]]
145 keys = "SPC b n"
146 command = "app.buffer.next"
147 mode = "normal"
148 [[bind]]
149 keys = "SPC b p"
150 command = "app.buffer.previous"
151 mode = "normal"
152 [[bind]]
153 keys = "SPC b ]"
154 command = "app.buffer.next"
155 mode = "normal"
156 [[bind]]
157 keys = "SPC b ["
158 command = "app.buffer.previous"
159 mode = "normal"
160 [[bind]]
161 keys = "] b"
162 command = "app.buffer.next"
163 mode = "normal"
164 [[bind]]
165 keys = "[ b"
166 command = "app.buffer.previous"
167 mode = "normal"
168 [[bind]]
169 keys = "SPC b s"
170 command = "app.save"
171 mode = "normal"
172 [[bind]]
173 keys = "SPC b S"
174 command = "app.save-all"
175 mode = "normal"
176 [[bind]]
177 keys = "SPC s s"
178 command = "edit.find"
179 mode = "normal"
180 [[bind]]
181 keys = "SPC /"
182 command = "app.search"
183 mode = "normal"
184 [[bind]]
185 keys = "SPC s p"
186 command = "app.search"
187 mode = "normal"
188 [[bind]]
189 keys = "SPC :"
190 command = "app.palette"
191 mode = "normal"
192 [[bind]]
193 keys = "SPC o a"
194 command = "app.agenda"
195 mode = "normal"
196 [[bind]]
197 keys = "SPC X"
198 command = "app.capture"
199 mode = "normal"
200 [[bind]]
201 keys = "SPC z t"
202 command = "app.clock.report"
203 mode = "normal"
204 [[bind]]
205 keys = "SPC h r r"
206 command = "app.reload-keymap"
207 mode = "normal"
208 [[bind]]
209 keys = "SPC t s"
210 command = "editor.toggle-spell-check"
211 mode = "normal"
212 [[bind]]
213 keys = "SPC t w"
214 command = "editor.toggle-truncate-lines"
215 mode = "normal"
216
217 # Localleader (SPC m)
218 [[bind]]
219 keys = "SPC m '"
220 command = "org.edit-special"
221 mode = "normal"
222 [[bind]]
223 keys = "SPC m s c"
224 command = "org.subtree.clone"
225 mode = "normal"
226 [[bind]]
227 keys = "SPC m s d"
228 command = "org.subtree.cut"
229 mode = "normal"
230 [[bind]]
231 keys = "SPC m s S"
232 command = "org.sort"
233 mode = "normal"
234 [[bind]]
235 keys = "SPC m s n"
236 command = "org.narrow.subtree"
237 mode = "normal"
238 [[bind]]
239 keys = "SPC m s s"
240 command = "org.sparse-tree"
241 mode = "normal"
242 [[bind]]
243 keys = "SPC m s N"
244 command = "org.widen"
245 mode = "normal"
246 [[bind]]
247 keys = "SPC m ."
248 command = "org.goto"
249 mode = "normal"
250 [[bind]]
251 keys = "SPC m h"
252 command = "org.heading.toggle"
253 mode = "normal"
254 [[bind]]
255 keys = "SPC m i"
256 command = "org.item.toggle"
257 mode = "normal"
258 [[bind]]
259 keys = "SPC m l l"
260 command = "org.link.insert"
261 mode = "normal"
262 [[bind]]
263 keys = "SPC m l s"
264 command = "org.link.store"
265 mode = "normal"
266 [[bind]]
267 keys = "SPC m l i"
268 command = "org.id.store-link"
269 mode = "normal"
270 [[bind]]
271 keys = "SPC n l"
272 command = "org.link.store"
273 mode = "normal"
274 [[bind]]
275 keys = "SPC m t"
276 command = "org.todo.cycle"
277 mode = "normal"
278 [[bind]]
279 keys = "SPC m q"
280 command = "org.tags.set"
281 mode = "normal"
282 [[bind]]
283 keys = "SPC m x"
284 command = "org.checkbox.toggle"
285 mode = "normal"
286 [[bind]]
287 keys = "SPC m A"
288 command = "app.archive"
289 mode = "normal"
290 [[bind]]
291 keys = "SPC m e h h"
292 command = "app.export.html"
293 mode = "normal"
294 [[bind]]
295 keys = "SPC m e h o"
296 command = "app.export.html-open"
297 mode = "normal"
298 [[bind]]
299 keys = "SPC m e m m"
300 command = "app.export.markdown"
301 mode = "normal"
302 [[bind]]
303 keys = "SPC m e l p"
304 command = "app.export.pdf"
305 mode = "normal"
306 [[bind]]
307 keys = "SPC m d d"
308 command = "org.deadline"
309 mode = "normal"
310 [[bind]]
311 keys = "SPC m d s"
312 command = "org.schedule"
313 mode = "normal"
314 [[bind]]
315 keys = "SPC m d t"
316 command = "org.timestamp.active"
317 mode = "normal"
318 [[bind]]
319 keys = "SPC m d T"
320 command = "org.timestamp.inactive"
321 mode = "normal"
322 [[bind]]
323 keys = "SPC m r r"
324 command = "app.refile"
325 mode = "normal"
326 [[bind]]
327 keys = "SPC m s r"
328 command = "app.refile"
329 mode = "normal"
330 [[bind]]
331 keys = "SPC m s A"
332 command = "app.archive"
333 mode = "normal"
334 [[bind]]
335 keys = "SPC m s a"
336 command = "org.archive.toggle-tag"
337 mode = "normal"
338 [[bind]]
339 keys = "SPC m s h"
340 command = "org.subtree.promote"
341 mode = "normal"
342 [[bind]]
343 keys = "SPC m s l"
344 command = "org.subtree.demote"
345 mode = "normal"
346 [[bind]]
347 keys = "SPC m s j"
348 command = "org.subtree.down"
349 mode = "normal"
350 [[bind]]
351 keys = "SPC m s k"
352 command = "org.subtree.up"
353 mode = "normal"
354 [[bind]]
355 keys = "SPC m c i"
356 command = "app.clock.in"
357 mode = "normal"
358 [[bind]]
359 keys = "SPC m c o"
360 command = "app.clock.out"
361 mode = "normal"
362 [[bind]]
363 keys = "SPC m c c"
364 command = "app.clock.cancel"
365 mode = "normal"
366 [[bind]]
367 keys = "SPC m c g"
368 command = "app.clock.goto"
369 mode = "normal"
370 [[bind]]
371 keys = "SPC m c G"
372 command = "app.clock.goto-recent"
373 mode = "normal"
374 [[bind]]
375 keys = "SPC m c I"
376 command = "app.clock.in-last"
377 mode = "normal"
378 [[bind]]
379 keys = "SPC m c d"
380 command = "app.clock.default"
381 mode = "normal"
382 [[bind]]
383 keys = "SPC m c r"
384 command = "app.clock.resolve"
385 mode = "normal"
386 [[bind]]
387 keys = "SPC m c R"
388 command = "app.clock.report"
389 mode = "normal"
390 [[bind]]
391 keys = "SPC m c E"
392 command = "org.effort.set"
393 mode = "normal"
394 [[bind]]
395 keys = "SPC m p p"
396 command = "org.priority.set"
397 mode = "normal"
398 [[bind]]
399 keys = "SPC m o"
400 command = "org.property.read-and-set"
401 mode = "normal"
402 [[bind]]
403 keys = "SPC m p u"
404 command = "org.priority.up"
405 mode = "normal"
406 [[bind]]
407 keys = "SPC m p d"
408 command = "org.priority.down"
409 mode = "normal"
410 [[bind]]
411 keys = "SPC m b -"
412 command = "org.table.insert-hline"
413 mode = "normal"
414 [[bind]]
415 keys = "SPC m b a"
416 command = "org.table.align"
417 mode = "normal"
418 [[bind]]
419 keys = "SPC m b r"
420 command = "org.table.recalc-all"
421 mode = "normal"
422 [[bind]]
423 keys = "SPC m b d c"
424 command = "org.table.delete-column"
425 mode = "normal"
426 [[bind]]
427 keys = "SPC m b d r"
428 command = "org.table.kill-row"
429 mode = "normal"
430 [[bind]]
431 keys = "SPC m b i c"
432 command = "org.table.insert-column"
433 mode = "normal"
434 [[bind]]
435 keys = "SPC m b i r"
436 command = "org.table.insert-row"
437 mode = "normal"
438 [[bind]]
439 keys = "SPC m b i h"
440 command = "org.table.insert-hline"
441 mode = "normal"
442
443 # evil-org and Doom's org keys
444 [[bind]]
445 keys = "TAB"
446 command = "org.cycle"
447 mode = "normal"
448 [[bind]]
449 keys = "S-TAB"
450 command = "org.cycle-global"
451 mode = "normal"
452 [[bind]]
453 keys = "RET"
454 command = "org.dwim"
455 mode = "normal"
456 [[bind]]
457 keys = "z a"
458 command = "org.fold.toggle"
459 mode = "normal"
460 [[bind]]
461 keys = "z c"
462 command = "org.fold.close"
463 mode = "normal"
464 [[bind]]
465 keys = "z o"
466 command = "org.fold.open"
467 mode = "normal"
468 [[bind]]
469 keys = "z A"
470 command = "org.cycle-global"
471 mode = "normal"
472 [[bind]]
473 keys = "g h"
474 command = "org.heading.up"
475 mode = "normal"
476 [[bind]]
477 keys = "] h"
478 command = "org.heading.forward-same-level"
479 mode = "normal"
480 [[bind]]
481 keys = "[ h"
482 command = "org.heading.backward-same-level"
483 mode = "normal"
484 [[bind]]
485 keys = "RET"
486 command = "org.table.next-row"
487 when = "table"
488 mode = "insert"
489 [[bind]]
490 keys = "TAB"
491 command = "org.cycle"
492 mode = "visual"
493 [[bind]]
494 keys = "S-TAB"
495 command = "org.cycle-global"
496 mode = "visual"
497
498 # Doom's corfu: completion-at-point in insert state.
499 [[bind]]
500 keys = "C-SPC"
501 command = "editor.complete"
502 mode = "insert"
503 [[bind]]
504 keys = "C-@"
505 command = "editor.complete"
506 mode = "insert"
507
508 # Insert state: org-cycle and org-shifttab with Doom's +org-indent-maybe-h, which
509 # demotes or promotes a heading and indents or outdents an item tree.
510 [[bind]]
511 keys = "S-TAB"
512 command = "org.cycle-global"
513 mode = "insert"
514 [[bind]]
515 keys = "TAB"
516 command = "org.table.next-field"
517 when = "table"
518 mode = "insert"
519 [[bind]]
520 keys = "S-TAB"
521 command = "org.table.previous-field"
522 when = "table"
523 mode = "insert"
524 [[bind]]
525 keys = "TAB"
526 command = "org.item.indent-tree"
527 when = "item"
528 mode = "insert"
529 [[bind]]
530 keys = "S-TAB"
531 command = "org.item.outdent-tree"
532 when = "item"
533 mode = "insert"
534 [[bind]]
535 keys = "TAB"
536 command = "org.heading.demote"
537 when = "heading"
538 mode = "insert"
539 [[bind]]
540 keys = "S-TAB"
541 command = "org.heading.promote"
542 when = "heading"
543 mode = "insert"
544
545 """
546}