Sources/OrgCore/Keymap/Presets.swift

8c221170c5ed1f01bcb7cabccac77177aa399d9a
orgstar/Sources/OrgCore/Keymap/Presets.swift history · blame · raw

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