Sources/OrgCore/Keymap/PresetDoom.swift

58f3b73e8ff337e5a15111fbb32c0d57cf2346da
orgstar/Sources/OrgCore/Keymap/PresetDoom.swift history · blame · raw

674 lines · 19059 bytes

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