Sources/OrgCore/Keymap/PresetDoom.swift
586 lines · 16686 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: "\\\\").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 a a"
224 command = "app.attach.attach"
225 mode = "normal"
226 [[bind]]
227 keys = "SPC m a d"
228 command = "app.attach.delete"
229 mode = "normal"
230 [[bind]]
231 keys = "SPC m a D"
232 command = "app.attach.delete-all"
233 mode = "normal"
234 [[bind]]
235 keys = "SPC m a n"
236 command = "app.attach.new"
237 mode = "normal"
238 [[bind]]
239 keys = "SPC m a o"
240 command = "app.attach.open"
241 mode = "normal"
242 [[bind]]
243 keys = "SPC m a r"
244 command = "app.attach.reveal"
245 mode = "normal"
246 [[bind]]
247 keys = "SPC m a u"
248 command = "app.attach.url"
249 mode = "normal"
250 [[bind]]
251 keys = "SPC m a s"
252 command = "app.attach.set-directory"
253 mode = "normal"
254 [[bind]]
255 keys = "SPC m a S"
256 command = "app.attach.sync"
257 mode = "normal"
258 [[bind]]
259 keys = "SPC m s c"
260 command = "org.subtree.clone"
261 mode = "normal"
262 [[bind]]
263 keys = "SPC m s d"
264 command = "org.subtree.cut"
265 mode = "normal"
266 [[bind]]
267 keys = "SPC m s S"
268 command = "org.sort"
269 mode = "normal"
270 [[bind]]
271 keys = "SPC m s n"
272 command = "org.narrow.subtree"
273 mode = "normal"
274 [[bind]]
275 keys = "SPC m s s"
276 command = "org.sparse-tree"
277 mode = "normal"
278 [[bind]]
279 keys = "SPC m s N"
280 command = "org.widen"
281 mode = "normal"
282 [[bind]]
283 keys = "SPC m ."
284 command = "org.goto"
285 mode = "normal"
286 [[bind]]
287 keys = "SPC m h"
288 command = "org.heading.toggle"
289 mode = "normal"
290 [[bind]]
291 keys = "SPC m i"
292 command = "org.item.toggle"
293 mode = "normal"
294 [[bind]]
295 keys = "SPC m l l"
296 command = "org.link.insert"
297 mode = "normal"
298 [[bind]]
299 keys = "SPC m l s"
300 command = "org.link.store"
301 mode = "normal"
302 [[bind]]
303 keys = "SPC m l i"
304 command = "org.id.store-link"
305 mode = "normal"
306 [[bind]]
307 keys = "SPC n l"
308 command = "org.link.store"
309 mode = "normal"
310 [[bind]]
311 keys = "SPC m t"
312 command = "org.todo.cycle"
313 mode = "normal"
314 [[bind]]
315 keys = "SPC m q"
316 command = "org.tags.set"
317 mode = "normal"
318 [[bind]]
319 keys = "SPC m x"
320 command = "org.checkbox.toggle"
321 mode = "normal"
322 [[bind]]
323 keys = "SPC m A"
324 command = "app.archive"
325 mode = "normal"
326 [[bind]]
327 keys = "SPC m e h h"
328 command = "app.export.html"
329 mode = "normal"
330 [[bind]]
331 keys = "SPC m e h o"
332 command = "app.export.html-open"
333 mode = "normal"
334 [[bind]]
335 keys = "SPC m e m m"
336 command = "app.export.markdown"
337 mode = "normal"
338 [[bind]]
339 keys = "SPC m e l p"
340 command = "app.export.pdf"
341 mode = "normal"
342 [[bind]]
343 keys = "SPC m d d"
344 command = "org.deadline"
345 mode = "normal"
346 [[bind]]
347 keys = "SPC m d s"
348 command = "org.schedule"
349 mode = "normal"
350 [[bind]]
351 keys = "SPC m d t"
352 command = "org.timestamp.active"
353 mode = "normal"
354 [[bind]]
355 keys = "SPC m d T"
356 command = "org.timestamp.inactive"
357 mode = "normal"
358 [[bind]]
359 keys = "SPC m r r"
360 command = "app.refile"
361 mode = "normal"
362 [[bind]]
363 keys = "SPC u SPC m r r"
364 command = "app.refile.goto"
365 mode = "normal"
366 [[bind]]
367 keys = "SPC m s r"
368 command = "app.refile"
369 mode = "normal"
370 [[bind]]
371 keys = "SPC m s A"
372 command = "app.archive"
373 mode = "normal"
374 [[bind]]
375 keys = "SPC m s a"
376 command = "org.archive.toggle-tag"
377 mode = "normal"
378 [[bind]]
379 keys = "SPC m s h"
380 command = "org.subtree.promote"
381 mode = "normal"
382 [[bind]]
383 keys = "SPC m s l"
384 command = "org.subtree.demote"
385 mode = "normal"
386 [[bind]]
387 keys = "SPC m s j"
388 command = "org.subtree.down"
389 mode = "normal"
390 [[bind]]
391 keys = "SPC m s k"
392 command = "org.subtree.up"
393 mode = "normal"
394 [[bind]]
395 keys = "SPC m c i"
396 command = "app.clock.in"
397 mode = "normal"
398 [[bind]]
399 keys = "SPC m c o"
400 command = "app.clock.out"
401 mode = "normal"
402 [[bind]]
403 keys = "SPC m c c"
404 command = "app.clock.cancel"
405 mode = "normal"
406 [[bind]]
407 keys = "SPC m c g"
408 command = "app.clock.goto"
409 mode = "normal"
410 [[bind]]
411 keys = "SPC m c G"
412 command = "app.clock.goto-recent"
413 mode = "normal"
414 [[bind]]
415 keys = "SPC m c I"
416 command = "app.clock.in-last"
417 mode = "normal"
418 [[bind]]
419 keys = "SPC m c d"
420 command = "app.clock.default"
421 mode = "normal"
422 [[bind]]
423 keys = "SPC m c r"
424 command = "app.clock.resolve"
425 mode = "normal"
426 [[bind]]
427 keys = "SPC m c R"
428 command = "app.clock.report"
429 mode = "normal"
430 [[bind]]
431 keys = "SPC m c E"
432 command = "org.effort.set"
433 mode = "normal"
434 [[bind]]
435 keys = "SPC m p p"
436 command = "org.priority.set"
437 mode = "normal"
438 [[bind]]
439 keys = "SPC m o"
440 command = "org.property.read-and-set"
441 mode = "normal"
442 [[bind]]
443 keys = "SPC m p u"
444 command = "org.priority.up"
445 mode = "normal"
446 [[bind]]
447 keys = "SPC m p d"
448 command = "org.priority.down"
449 mode = "normal"
450 [[bind]]
451 keys = "SPC m b -"
452 command = "org.table.insert-hline"
453 mode = "normal"
454 [[bind]]
455 keys = "SPC m b a"
456 command = "org.table.align"
457 mode = "normal"
458 [[bind]]
459 keys = "SPC m b r"
460 command = "org.table.recalc-all"
461 mode = "normal"
462 [[bind]]
463 keys = "SPC m b d c"
464 command = "org.table.delete-column"
465 mode = "normal"
466 [[bind]]
467 keys = "SPC m b d r"
468 command = "org.table.kill-row"
469 mode = "normal"
470 [[bind]]
471 keys = "SPC m b i c"
472 command = "org.table.insert-column"
473 mode = "normal"
474 [[bind]]
475 keys = "SPC m b i r"
476 command = "org.table.insert-row"
477 mode = "normal"
478 [[bind]]
479 keys = "SPC m b i h"
480 command = "org.table.insert-hline"
481 mode = "normal"
482
483 # evil-org and Doom's org keys
484 [[bind]]
485 keys = "TAB"
486 command = "org.cycle"
487 mode = "normal"
488 [[bind]]
489 keys = "S-TAB"
490 command = "org.cycle-global"
491 mode = "normal"
492 [[bind]]
493 keys = "RET"
494 command = "org.dwim"
495 mode = "normal"
496 [[bind]]
497 keys = "z a"
498 command = "org.fold.toggle"
499 mode = "normal"
500 [[bind]]
501 keys = "z c"
502 command = "org.fold.close"
503 mode = "normal"
504 [[bind]]
505 keys = "z o"
506 command = "org.fold.open"
507 mode = "normal"
508 [[bind]]
509 keys = "z A"
510 command = "org.cycle-global"
511 mode = "normal"
512 [[bind]]
513 keys = "g h"
514 command = "org.heading.up"
515 mode = "normal"
516 [[bind]]
517 keys = "] h"
518 command = "org.heading.forward-same-level"
519 mode = "normal"
520 [[bind]]
521 keys = "[ h"
522 command = "org.heading.backward-same-level"
523 mode = "normal"
524 [[bind]]
525 keys = "RET"
526 command = "org.table.next-row"
527 when = "table"
528 mode = "insert"
529 [[bind]]
530 keys = "TAB"
531 command = "org.cycle"
532 mode = "visual"
533 [[bind]]
534 keys = "S-TAB"
535 command = "org.cycle-global"
536 mode = "visual"
537
538 # Doom's corfu: completion-at-point in insert state.
539 [[bind]]
540 keys = "C-SPC"
541 command = "editor.complete"
542 mode = "insert"
543 [[bind]]
544 keys = "C-@"
545 command = "editor.complete"
546 mode = "insert"
547
548 # Insert state: org-cycle and org-shifttab with Doom's +org-indent-maybe-h, which
549 # demotes or promotes a heading and indents or outdents an item tree.
550 [[bind]]
551 keys = "S-TAB"
552 command = "org.cycle-global"
553 mode = "insert"
554 [[bind]]
555 keys = "TAB"
556 command = "org.table.next-field"
557 when = "table"
558 mode = "insert"
559 [[bind]]
560 keys = "S-TAB"
561 command = "org.table.previous-field"
562 when = "table"
563 mode = "insert"
564 [[bind]]
565 keys = "TAB"
566 command = "org.item.indent-tree"
567 when = "item"
568 mode = "insert"
569 [[bind]]
570 keys = "S-TAB"
571 command = "org.item.outdent-tree"
572 when = "item"
573 mode = "insert"
574 [[bind]]
575 keys = "TAB"
576 command = "org.heading.demote"
577 when = "heading"
578 mode = "insert"
579 [[bind]]
580 keys = "S-TAB"
581 command = "org.heading.promote"
582 when = "heading"
583 mode = "insert"
584
585 """
586}