Sources/OrgCore/Keymap/Presets.swift

3959d9c38d34f2d30757a8c9c88309a5328522e5
orgstar/Sources/OrgCore/Keymap/Presets.swift history · blame · raw

995 lines · 27525 bytes

  1/// The keymaps the app ships. The user's `keymap.toml` is layered on top of the chosen one.
  2public enum KeymapPreset: String, Sendable, CaseIterable {
  3    case emacs, mac, doom
  4
  5    public var title: String {
  6        switch self {
  7        case .emacs: "Emacs"
  8        case .mac: "Mac"
  9        case .doom: "Doom (Vim keys)"
 10        }
 11    }
 12
 13    /// Whether the preset edits modally.
 14    public var isModal: Bool { self == .doom }
 15
 16    public var keymap: Keymap {
 17        var problems: [String] = []
 18        let map = try! Keymap(toml: toml, problems: &problems)
 19        precondition(problems.isEmpty, "preset \(rawValue): \(problems)")
 20        return map
 21    }
 22
 23    public var toml: String {
 24        switch self {
 25        case .emacs: Self.common + Self.emacsBindings
 26        case .mac: Self.common + Self.macBindings
 27        case .doom: Self.doomToml
 28        }
 29    }
 30
 31    /// Doom: the Emacs preset's org bindings in every evil state (as org-mode-map's are), with
 32    /// evil-org's `M-h/j/k/l` forms, then Doom's leader, localleader and evil-org keys.
 33    static var doomToml: String {
 34        var problems: [String] = []
 35        let emacs = try! Keymap(toml: common + emacsBindings, problems: &problems)
 36        let translations: [String: String] = ["<left>": "h", "<right>": "l", "<up>": "k", "<down>": "j"]
 37        var out = ""
 38        func bind(_ keys: String, _ command: String, when: String?, mode: String) {
 39            out += "[[bind]]\nkeys = \"\(keys.replacingOccurrences(of: "\\", with: "\\\\"))\"\ncommand = \"\(command)\"\n"
 40            if let when { out += "when = \"\(when)\"\n" }
 41            out += "mode = \"\(mode)\"\n"
 42        }
 43        for binding in emacs.bindings {
 44            let first = binding.keys[0]
 45            let keys = KeySequence.format(binding.keys)
 46            let orgKey = first.key == "c" && first.modifiers == [.control] || first.key == "x" && first.modifiers == [.control]
 47                || (first.modifiers.contains(.meta) && ["<left>", "<right>", "<up>", "<down>", "RET"].contains(first.key))
 48                || (first.modifiers.contains(.shift) && ["<left>", "<right>", "<up>", "<down>"].contains(first.key))
 49                || (first.modifiers == [.control] && first.key == "RET")
 50                || keys == "M-x"
 51            guard orgKey else { continue }
 52            for mode in ["normal", "insert", "visual"] { bind(keys, binding.command, when: binding.when, mode: mode) }
 53            // evil-org: M-h/j/k/l and M-H/J/K/L in normal, visual and insert.
 54            if binding.keys.count == 1, first.modifiers.contains(.meta), let letter = translations[first.key] {
 55                let shifted = first.modifiers.contains(.shift)
 56                let key = "M-" + (shifted ? letter.uppercased() : letter)
 57                for mode in ["normal", "insert", "visual"] { bind(key, binding.command, when: binding.when, mode: mode) }
 58            }
 59            // Doom: C-S-h/j/k/l are org-shift* in normal and insert.
 60            if binding.keys.count == 1, first.modifiers == [.shift], let letter = translations[first.key] {
 61                for mode in ["normal", "insert"] { bind("C-" + letter.uppercased(), binding.command, when: binding.when, mode: mode) }
 62            }
 63            // evil-org insert state: C-t demotes, C-d promotes.
 64            if binding.keys.count == 1, first.modifiers == [.meta], first.key == "<right>" || first.key == "<left>" {
 65                bind(first.key == "<right>" ? "C-t" : "C-d", binding.command, when: binding.when, mode: "insert")
 66            }
 67        }
 68        return out + doomBindings
 69    }
 70
 71    static let doomBindings = """
 72        # Leader
 73        [[bind]]
 74        keys = "SPC SPC"
 75        command = "app.quick-open"
 76        mode = "normal"
 77        [[bind]]
 78        keys = "SPC q q"
 79        command = "app.quit"
 80        mode = "normal"
 81        [[bind]]
 82        keys = "SPC ."
 83        command = "app.quick-open"
 84        mode = "normal"
 85        [[bind]]
 86        keys = "SPC f f"
 87        command = "app.quick-open"
 88        mode = "normal"
 89        [[bind]]
 90        keys = "SPC b b"
 91        command = "app.quick-open"
 92        mode = "normal"
 93        [[bind]]
 94        keys = "SPC f s"
 95        command = "app.save"
 96        mode = "normal"
 97        # Buffers
 98        [[bind]]
 99        keys = "SPC b b"
100        command = "app.buffer.switch"
101        mode = "normal"
102        [[bind]]
103        keys = "SPC b B"
104        command = "app.buffer.switch"
105        mode = "normal"
106        [[bind]]
107        keys = "SPC ,"
108        command = "app.buffer.switch"
109        mode = "normal"
110        [[bind]]
111        keys = "SPC `"
112        command = "app.buffer.last"
113        mode = "normal"
114        [[bind]]
115        keys = "SPC b k"
116        command = "app.buffer.kill"
117        mode = "normal"
118        [[bind]]
119        keys = "SPC b d"
120        command = "app.buffer.kill"
121        mode = "normal"
122        [[bind]]
123        keys = "SPC b K"
124        command = "app.buffer.kill-all"
125        mode = "normal"
126        [[bind]]
127        keys = "SPC b O"
128        command = "app.buffer.kill-others"
129        mode = "normal"
130        [[bind]]
131        keys = "SPC b n"
132        command = "app.buffer.next"
133        mode = "normal"
134        [[bind]]
135        keys = "SPC b p"
136        command = "app.buffer.previous"
137        mode = "normal"
138        [[bind]]
139        keys = "SPC b ]"
140        command = "app.buffer.next"
141        mode = "normal"
142        [[bind]]
143        keys = "SPC b ["
144        command = "app.buffer.previous"
145        mode = "normal"
146        [[bind]]
147        keys = "] b"
148        command = "app.buffer.next"
149        mode = "normal"
150        [[bind]]
151        keys = "[ b"
152        command = "app.buffer.previous"
153        mode = "normal"
154        [[bind]]
155        keys = "SPC b s"
156        command = "app.save"
157        mode = "normal"
158        [[bind]]
159        keys = "SPC b S"
160        command = "app.save-all"
161        mode = "normal"
162        [[bind]]
163        keys = "SPC s s"
164        command = "edit.find"
165        mode = "normal"
166        [[bind]]
167        keys = "SPC /"
168        command = "app.search"
169        mode = "normal"
170        [[bind]]
171        keys = "SPC s p"
172        command = "app.search"
173        mode = "normal"
174        [[bind]]
175        keys = "SPC :"
176        command = "app.palette"
177        mode = "normal"
178        [[bind]]
179        keys = "SPC o a"
180        command = "app.agenda"
181        mode = "normal"
182        [[bind]]
183        keys = "SPC X"
184        command = "app.capture"
185        mode = "normal"
186        [[bind]]
187        keys = "SPC z t"
188        command = "app.clock.report"
189        mode = "normal"
190        [[bind]]
191        keys = "SPC h r r"
192        command = "app.reload-keymap"
193        mode = "normal"
194
195        # Localleader (SPC m)
196        [[bind]]
197        keys = "SPC m t"
198        command = "org.todo.cycle"
199        mode = "normal"
200        [[bind]]
201        keys = "SPC m q"
202        command = "org.tags.set"
203        mode = "normal"
204        [[bind]]
205        keys = "SPC m x"
206        command = "org.checkbox.toggle"
207        mode = "normal"
208        [[bind]]
209        keys = "SPC m A"
210        command = "app.archive"
211        mode = "normal"
212        [[bind]]
213        keys = "SPC m e h h"
214        command = "app.export.html"
215        mode = "normal"
216        [[bind]]
217        keys = "SPC m e h o"
218        command = "app.export.html-open"
219        mode = "normal"
220        [[bind]]
221        keys = "SPC m e m m"
222        command = "app.export.markdown"
223        mode = "normal"
224        [[bind]]
225        keys = "SPC m e l p"
226        command = "app.export.pdf"
227        mode = "normal"
228        [[bind]]
229        keys = "SPC m d d"
230        command = "org.deadline"
231        mode = "normal"
232        [[bind]]
233        keys = "SPC m d s"
234        command = "org.schedule"
235        mode = "normal"
236        [[bind]]
237        keys = "SPC m d t"
238        command = "org.timestamp.active"
239        mode = "normal"
240        [[bind]]
241        keys = "SPC m d T"
242        command = "org.timestamp.inactive"
243        mode = "normal"
244        [[bind]]
245        keys = "SPC m r r"
246        command = "app.refile"
247        mode = "normal"
248        [[bind]]
249        keys = "SPC m s r"
250        command = "app.refile"
251        mode = "normal"
252        [[bind]]
253        keys = "SPC m s A"
254        command = "app.archive"
255        mode = "normal"
256        [[bind]]
257        keys = "SPC m s h"
258        command = "org.subtree.promote"
259        mode = "normal"
260        [[bind]]
261        keys = "SPC m s l"
262        command = "org.subtree.demote"
263        mode = "normal"
264        [[bind]]
265        keys = "SPC m s j"
266        command = "org.subtree.down"
267        mode = "normal"
268        [[bind]]
269        keys = "SPC m s k"
270        command = "org.subtree.up"
271        mode = "normal"
272        [[bind]]
273        keys = "SPC m c i"
274        command = "app.clock.in"
275        mode = "normal"
276        [[bind]]
277        keys = "SPC m c o"
278        command = "app.clock.out"
279        mode = "normal"
280        [[bind]]
281        keys = "SPC m c c"
282        command = "app.clock.cancel"
283        mode = "normal"
284        [[bind]]
285        keys = "SPC m c g"
286        command = "app.clock.goto"
287        mode = "normal"
288        [[bind]]
289        keys = "SPC m c R"
290        command = "app.clock.report"
291        mode = "normal"
292        [[bind]]
293        keys = "SPC m p u"
294        command = "org.priority.up"
295        mode = "normal"
296        [[bind]]
297        keys = "SPC m p d"
298        command = "org.priority.down"
299        mode = "normal"
300        [[bind]]
301        keys = "SPC m b -"
302        command = "org.table.insert-hline"
303        mode = "normal"
304        [[bind]]
305        keys = "SPC m b a"
306        command = "org.table.align"
307        mode = "normal"
308        [[bind]]
309        keys = "SPC m b r"
310        command = "org.table.recalc-all"
311        mode = "normal"
312        [[bind]]
313        keys = "SPC m b d c"
314        command = "org.table.delete-column"
315        mode = "normal"
316        [[bind]]
317        keys = "SPC m b d r"
318        command = "org.table.kill-row"
319        mode = "normal"
320        [[bind]]
321        keys = "SPC m b i c"
322        command = "org.table.insert-column"
323        mode = "normal"
324        [[bind]]
325        keys = "SPC m b i r"
326        command = "org.table.insert-row"
327        mode = "normal"
328        [[bind]]
329        keys = "SPC m b i h"
330        command = "org.table.insert-hline"
331        mode = "normal"
332
333        # evil-org and Doom's org keys
334        [[bind]]
335        keys = "TAB"
336        command = "org.cycle"
337        mode = "normal"
338        [[bind]]
339        keys = "S-TAB"
340        command = "org.cycle-global"
341        mode = "normal"
342        [[bind]]
343        keys = "RET"
344        command = "org.dwim"
345        mode = "normal"
346        [[bind]]
347        keys = "z a"
348        command = "org.cycle"
349        mode = "normal"
350        [[bind]]
351        keys = "z c"
352        command = "org.cycle"
353        mode = "normal"
354        [[bind]]
355        keys = "z o"
356        command = "org.cycle"
357        mode = "normal"
358        [[bind]]
359        keys = "z A"
360        command = "org.cycle-global"
361        mode = "normal"
362        [[bind]]
363        keys = "g h"
364        command = "org.heading.up"
365        mode = "normal"
366        [[bind]]
367        keys = "g j"
368        command = "org.heading.forward-same-level"
369        mode = "normal"
370        [[bind]]
371        keys = "g k"
372        command = "org.heading.backward-same-level"
373        mode = "normal"
374        [[bind]]
375        keys = "] h"
376        command = "org.heading.forward-same-level"
377        mode = "normal"
378        [[bind]]
379        keys = "[ h"
380        command = "org.heading.backward-same-level"
381        mode = "normal"
382        [[bind]]
383        keys = "RET"
384        command = "org.table.next-row"
385        when = "table"
386        mode = "insert"
387        [[bind]]
388        keys = "TAB"
389        command = "org.cycle"
390        mode = "visual"
391        [[bind]]
392        keys = "S-TAB"
393        command = "org.cycle-global"
394        mode = "visual"
395
396        # Insert state: org-cycle and org-shifttab with Doom's +org-indent-maybe-h, which
397        # demotes or promotes a heading and indents or outdents an item tree.
398        [[bind]]
399        keys = "S-TAB"
400        command = "org.cycle-global"
401        mode = "insert"
402        [[bind]]
403        keys = "TAB"
404        command = "org.table.next-field"
405        when = "table"
406        mode = "insert"
407        [[bind]]
408        keys = "S-TAB"
409        command = "org.table.previous-field"
410        when = "table"
411        mode = "insert"
412        [[bind]]
413        keys = "TAB"
414        command = "org.item.indent-tree"
415        when = "item"
416        mode = "insert"
417        [[bind]]
418        keys = "S-TAB"
419        command = "org.item.outdent-tree"
420        when = "item"
421        mode = "insert"
422        [[bind]]
423        keys = "TAB"
424        command = "org.heading.demote"
425        when = "heading"
426        mode = "insert"
427        [[bind]]
428        keys = "S-TAB"
429        command = "org.heading.promote"
430        when = "heading"
431        mode = "insert"
432
433        """
434
435
436    static let common = """
437        [[bind]]
438        keys = "TAB"
439        command = "org.cycle"
440        when = "heading"
441
442        [[bind]]
443        keys = "S-TAB"
444        command = "org.cycle-global"
445        [[bind]]
446        keys = "TAB"
447        command = "org.table.next-field"
448        when = "table"
449        [[bind]]
450        keys = "S-TAB"
451        command = "org.table.previous-field"
452        when = "table"
453        [[bind]]
454        keys = "RET"
455        command = "org.table.next-row"
456        when = "table"
457
458        """
459
460    static let emacsBindings = """
461        # Movement and editing. With a mark set (C-SPC), movement extends the region.
462        [[bind]]
463        keys = "C-f"
464        command = "edit.forward-char"
465        [[bind]]
466        keys = "C-b"
467        command = "edit.backward-char"
468        [[bind]]
469        keys = "C-n"
470        command = "edit.next-line"
471        [[bind]]
472        keys = "C-p"
473        command = "edit.previous-line"
474        [[bind]]
475        keys = "C-a"
476        command = "edit.beginning-of-line"
477        [[bind]]
478        keys = "C-e"
479        command = "edit.end-of-line"
480        [[bind]]
481        keys = "M-f"
482        command = "edit.forward-word"
483        [[bind]]
484        keys = "M-b"
485        command = "edit.backward-word"
486        [[bind]]
487        keys = "M-<"
488        command = "edit.beginning-of-buffer"
489        [[bind]]
490        keys = "M->"
491        command = "edit.end-of-buffer"
492        [[bind]]
493        keys = "C-v"
494        command = "edit.scroll-up"
495        [[bind]]
496        keys = "M-v"
497        command = "edit.scroll-down"
498        [[bind]]
499        keys = "C-l"
500        command = "edit.recenter"
501        [[bind]]
502        keys = "C-d"
503        command = "edit.delete-char"
504        [[bind]]
505        keys = "M-d"
506        command = "edit.kill-word"
507        [[bind]]
508        keys = "M-DEL"
509        command = "edit.backward-kill-word"
510        [[bind]]
511        keys = "C-k"
512        command = "edit.kill-line"
513        [[bind]]
514        keys = "C-y"
515        command = "edit.yank"
516        [[bind]]
517        keys = "C-SPC"
518        command = "edit.set-mark"
519        [[bind]]
520        keys = "C-x h"
521        command = "edit.select-all"
522        [[bind]]
523        keys = "C-w"
524        command = "edit.kill-region"
525        [[bind]]
526        keys = "M-w"
527        command = "edit.copy-region"
528        [[bind]]
529        keys = "C-/"
530        command = "edit.undo"
531        [[bind]]
532        keys = "C-_"
533        command = "edit.undo"
534        [[bind]]
535        keys = "C-x u"
536        command = "edit.undo"
537        [[bind]]
538        keys = "C-g"
539        command = "edit.keyboard-quit"
540        [[bind]]
541        keys = "C-t"
542        command = "edit.transpose-chars"
543        [[bind]]
544        keys = "C-s"
545        command = "edit.find"
546        [[bind]]
547        keys = "C-r"
548        command = "edit.find"
549        [[bind]]
550        keys = "M-%"
551        command = "edit.replace"
552
553        # Files and commands
554        [[bind]]
555        keys = "C-x C-s"
556        command = "app.save"
557        [[bind]]
558        keys = "C-x b"
559        command = "app.buffer.switch"
560        [[bind]]
561        keys = "C-x C-b"
562        command = "app.buffer.switch"
563        [[bind]]
564        keys = "C-x k"
565        command = "app.buffer.kill"
566        [[bind]]
567        keys = "C-x <right>"
568        command = "app.buffer.next"
569        [[bind]]
570        keys = "C-x <left>"
571        command = "app.buffer.previous"
572        [[bind]]
573        keys = "C-x s"
574        command = "app.save-all"
575        [[bind]]
576        keys = "C-x C-f"
577        command = "app.quick-open"
578        [[bind]]
579        keys = "C-x b"
580        command = "app.quick-open"
581        [[bind]]
582        keys = "M-x"
583        command = "app.palette"
584        [[bind]]
585        keys = "C-c a"
586        command = "app.agenda"
587        [[bind]]
588        keys = "C-c c"
589        command = "app.capture"
590        [[bind]]
591        keys = "C-c C-x C-i"
592        command = "app.clock.in"
593        [[bind]]
594        keys = "C-c C-x C-o"
595        command = "app.clock.out"
596        [[bind]]
597        keys = "C-c C-x C-q"
598        command = "app.clock.cancel"
599        [[bind]]
600        keys = "C-c C-x C-j"
601        command = "app.clock.goto"
602        [[bind]]
603        keys = "C-c C-e h h"
604        command = "app.export.html"
605        [[bind]]
606        keys = "C-c C-e h o"
607        command = "app.export.html-open"
608        [[bind]]
609        keys = "C-c C-e m m"
610        command = "app.export.markdown"
611        [[bind]]
612        keys = "C-c C-e l p"
613        command = "app.export.pdf"
614        [[bind]]
615        keys = "C-c C-e l l"
616        command = "app.export.latex"
617        [[bind]]
618        keys = "C-c C-e o o"
619        command = "app.export.odt"
620        [[bind]]
621        keys = "C-c C-e t u"
622        command = "app.export.text"
623
624        # Org
625        [[bind]]
626        keys = "C-c C-t"
627        command = "org.todo.cycle"
628        [[bind]]
629        keys = "S-<right>"
630        command = "org.todo.cycle"
631        when = "heading"
632        [[bind]]
633        keys = "S-<up>"
634        command = "org.priority.up"
635        when = "heading"
636        [[bind]]
637        keys = "S-<down>"
638        command = "org.priority.down"
639        when = "heading"
640        [[bind]]
641        keys = "M-<left>"
642        command = "org.heading.promote"
643        when = "heading"
644        [[bind]]
645        keys = "M-<right>"
646        command = "org.heading.demote"
647        when = "heading"
648        [[bind]]
649        keys = "M-S-<left>"
650        command = "org.subtree.promote"
651        when = "heading"
652        [[bind]]
653        keys = "M-S-<right>"
654        command = "org.subtree.demote"
655        when = "heading"
656        [[bind]]
657        keys = "M-<up>"
658        command = "org.subtree.up"
659        when = "heading"
660        [[bind]]
661        keys = "M-<down>"
662        command = "org.subtree.down"
663        when = "heading"
664        [[bind]]
665        keys = "M-RET"
666        command = "org.heading.insert"
667        [[bind]]
668        keys = "C-RET"
669        command = "org.heading.insert-after-subtree"
670        [[bind]]
671        keys = "M-S-RET"
672        command = "org.heading.insert-todo"
673        [[bind]]
674        keys = "C-c C-n"
675        command = "org.heading.next"
676        [[bind]]
677        keys = "C-c C-p"
678        command = "org.heading.previous"
679        [[bind]]
680        keys = "C-c C-f"
681        command = "org.heading.forward-same-level"
682        [[bind]]
683        keys = "C-c C-b"
684        command = "org.heading.backward-same-level"
685        [[bind]]
686        keys = "C-c C-u"
687        command = "org.heading.up"
688        [[bind]]
689        keys = "C-c C-q"
690        command = "org.tags.set"
691        [[bind]]
692        keys = "M-RET"
693        command = "org.item.insert"
694        when = "item"
695        [[bind]]
696        keys = "M-S-RET"
697        command = "org.item.insert-checkbox"
698        when = "item"
699        [[bind]]
700        keys = "M-<left>"
701        command = "org.item.outdent"
702        when = "item"
703        [[bind]]
704        keys = "M-<right>"
705        command = "org.item.indent"
706        when = "item"
707        [[bind]]
708        keys = "M-S-<left>"
709        command = "org.item.outdent-tree"
710        when = "item"
711        [[bind]]
712        keys = "M-S-<right>"
713        command = "org.item.indent-tree"
714        when = "item"
715        [[bind]]
716        keys = "M-<up>"
717        command = "org.item.up"
718        when = "item"
719        [[bind]]
720        keys = "M-<down>"
721        command = "org.item.down"
722        when = "item"
723        [[bind]]
724        keys = "C-c C-c"
725        command = "org.checkbox.toggle"
726        when = "item"
727        [[bind]]
728        keys = "C-c C-x C-b"
729        command = "org.checkbox.toggle"
730        [[bind]]
731        keys = "C-c C-w"
732        command = "app.refile"
733        [[bind]]
734        keys = "C-c C-x C-s"
735        command = "app.archive"
736        [[bind]]
737        keys = "C-c $"
738        command = "app.archive"
739        [[bind]]
740        keys = "C-c ."
741        command = "org.timestamp.active"
742        [[bind]]
743        keys = "C-c !"
744        command = "org.timestamp.inactive"
745        [[bind]]
746        keys = "C-c C-s"
747        command = "org.schedule"
748        [[bind]]
749        keys = "C-c C-d"
750        command = "org.deadline"
751        [[bind]]
752        keys = "M-q"
753        command = "org.fill-paragraph"
754        [[bind]]
755        keys = "C-c C-c"
756        command = "org.table.align"
757        when = "table"
758        [[bind]]
759        keys = "C-c C-c"
760        command = "org.table.recalc-all"
761        when = "tblfm"
762        [[bind]]
763        keys = "C-c *"
764        command = "org.table.recalc"
765        when = "table"
766        [[bind]]
767        keys = "C-c C-c"
768        command = "org.babel.execute"
769        when = "src"
770        [[bind]]
771        keys = "M-<up>"
772        command = "org.table.row-up"
773        when = "table"
774        [[bind]]
775        keys = "M-<down>"
776        command = "org.table.row-down"
777        when = "table"
778        [[bind]]
779        keys = "M-<left>"
780        command = "org.table.column-left"
781        when = "table"
782        [[bind]]
783        keys = "M-<right>"
784        command = "org.table.column-right"
785        when = "table"
786        [[bind]]
787        keys = "M-S-<right>"
788        command = "org.table.insert-column"
789        when = "table"
790        [[bind]]
791        keys = "M-S-<left>"
792        command = "org.table.delete-column"
793        when = "table"
794        [[bind]]
795        keys = "M-S-<up>"
796        command = "org.table.kill-row"
797        when = "table"
798        [[bind]]
799        keys = "M-S-<down>"
800        command = "org.table.insert-row"
801        when = "table"
802        [[bind]]
803        keys = "C-c -"
804        command = "org.table.insert-hline"
805        when = "table"
806        [[bind]]
807        keys = "C-c |"
808        command = "org.table.create"
809        [[bind]]
810        keys = "S-<up>"
811        command = "org.timestamp.up"
812        when = "timestamp"
813        [[bind]]
814        keys = "S-<down>"
815        command = "org.timestamp.down"
816        when = "timestamp"
817        [[bind]]
818        keys = "S-<right>"
819        command = "org.timestamp.day-later"
820        when = "timestamp"
821        [[bind]]
822        keys = "S-<left>"
823        command = "org.timestamp.day-earlier"
824        when = "timestamp"
825
826        """
827
828    /// Standard Mac text keys stay as they are; org commands use Control-Command chords, which
829    /// macOS text editing leaves free.
830    static let macBindings = """
831        [[bind]]
832        keys = "C-TAB"
833        command = "app.buffer.next"
834        [[bind]]
835        keys = "C-S-TAB"
836        command = "app.buffer.previous"
837        [[bind]]
838        keys = "C-s-t"
839        command = "org.todo.cycle"
840        [[bind]]
841        keys = "C-s-<up>"
842        command = "org.priority.up"
843        [[bind]]
844        keys = "C-s-<down>"
845        command = "org.priority.down"
846        [[bind]]
847        keys = "C-s-<left>"
848        command = "org.heading.promote"
849        [[bind]]
850        keys = "C-s-<right>"
851        command = "org.heading.demote"
852        [[bind]]
853        keys = "C-M-s-<left>"
854        command = "org.subtree.promote"
855        [[bind]]
856        keys = "C-M-s-<right>"
857        command = "org.subtree.demote"
858        [[bind]]
859        keys = "C-M-s-<up>"
860        command = "org.subtree.up"
861        [[bind]]
862        keys = "C-M-s-<down>"
863        command = "org.subtree.down"
864        [[bind]]
865        keys = "s-RET"
866        command = "org.heading.insert"
867        [[bind]]
868        keys = "C-s-RET"
869        command = "org.heading.insert-after-subtree"
870        [[bind]]
871        keys = "s-S-RET"
872        command = "org.heading.insert-todo"
873        [[bind]]
874        keys = "M-s-<down>"
875        command = "org.heading.next"
876        [[bind]]
877        keys = "M-s-<up>"
878        command = "org.heading.previous"
879        [[bind]]
880        keys = "C-s-q"
881        command = "org.tags.set"
882        [[bind]]
883        keys = "s-RET"
884        command = "org.item.insert"
885        when = "item"
886        [[bind]]
887        keys = "s-S-RET"
888        command = "org.item.insert-checkbox"
889        when = "item"
890        [[bind]]
891        keys = "C-s-<left>"
892        command = "org.item.outdent"
893        when = "item"
894        [[bind]]
895        keys = "C-s-<right>"
896        command = "org.item.indent"
897        when = "item"
898        [[bind]]
899        keys = "C-M-s-<left>"
900        command = "org.item.outdent-tree"
901        when = "item"
902        [[bind]]
903        keys = "C-M-s-<right>"
904        command = "org.item.indent-tree"
905        when = "item"
906        [[bind]]
907        keys = "C-M-s-<up>"
908        command = "org.item.up"
909        when = "item"
910        [[bind]]
911        keys = "C-M-s-<down>"
912        command = "org.item.down"
913        when = "item"
914        [[bind]]
915        keys = "C-s-c"
916        command = "org.checkbox.toggle"
917        [[bind]]
918        keys = "C-s-w"
919        command = "app.refile"
920        [[bind]]
921        keys = "C-s-a"
922        command = "app.archive"
923        [[bind]]
924        keys = "C-s-."
925        command = "org.timestamp.active"
926        [[bind]]
927        keys = "C-M-s-."
928        command = "org.timestamp.inactive"
929        [[bind]]
930        keys = "C-s-s"
931        command = "org.schedule"
932        [[bind]]
933        keys = "C-s-d"
934        command = "org.deadline"
935        [[bind]]
936        keys = "C-s-p"
937        command = "org.fill-paragraph"
938        [[bind]]
939        keys = "C-s-<up>"
940        command = "org.table.row-up"
941        when = "table"
942        [[bind]]
943        keys = "C-s-<down>"
944        command = "org.table.row-down"
945        when = "table"
946        [[bind]]
947        keys = "C-s-<left>"
948        command = "org.table.column-left"
949        when = "table"
950        [[bind]]
951        keys = "C-s-<right>"
952        command = "org.table.column-right"
953        when = "table"
954        [[bind]]
955        keys = "C-M-s-<right>"
956        command = "org.table.insert-column"
957        when = "table"
958        [[bind]]
959        keys = "C-M-s-<left>"
960        command = "org.table.delete-column"
961        when = "table"
962        [[bind]]
963        keys = "C-M-s-<up>"
964        command = "org.table.kill-row"
965        when = "table"
966        [[bind]]
967        keys = "C-M-s-<down>"
968        command = "org.table.insert-row"
969        when = "table"
970        [[bind]]
971        keys = "C-s--"
972        command = "org.table.insert-hline"
973        when = "table"
974        [[bind]]
975        keys = "C-s-\\\\"
976        command = "org.table.create"
977        [[bind]]
978        keys = "C-s-<up>"
979        command = "org.timestamp.up"
980        when = "timestamp"
981        [[bind]]
982        keys = "C-s-<down>"
983        command = "org.timestamp.down"
984        when = "timestamp"
985        [[bind]]
986        keys = "C-s-<right>"
987        command = "org.timestamp.day-later"
988        when = "timestamp"
989        [[bind]]
990        keys = "C-s-<left>"
991        command = "org.timestamp.day-earlier"
992        when = "timestamp"
993
994        """
995}