Sources/OrgCore/Keymap/Presets.swift

2cef47f82373d81f99d371b9aceb8bdc702f54c1
orgstar/Sources/OrgCore/Keymap/Presets.swift history · blame · raw

1142 lines · 31379 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 '"
 194        command = "org.edit-special"
 195        mode = "normal"
 196        [[bind]]
 197        keys = "SPC m s c"
 198        command = "org.subtree.clone"
 199        mode = "normal"
 200        [[bind]]
 201        keys = "SPC m s d"
 202        command = "org.subtree.cut"
 203        mode = "normal"
 204        [[bind]]
 205        keys = "SPC m s S"
 206        command = "org.sort"
 207        mode = "normal"
 208        [[bind]]
 209        keys = "SPC m s n"
 210        command = "org.narrow.subtree"
 211        mode = "normal"
 212        [[bind]]
 213        keys = "SPC m s s"
 214        command = "org.sparse-tree"
 215        mode = "normal"
 216        [[bind]]
 217        keys = "SPC m s N"
 218        command = "org.widen"
 219        mode = "normal"
 220        [[bind]]
 221        keys = "SPC m ."
 222        command = "org.goto"
 223        mode = "normal"
 224        [[bind]]
 225        keys = "SPC m h"
 226        command = "org.heading.toggle"
 227        mode = "normal"
 228        [[bind]]
 229        keys = "SPC m i"
 230        command = "org.item.toggle"
 231        mode = "normal"
 232        [[bind]]
 233        keys = "SPC m l l"
 234        command = "org.link.insert"
 235        mode = "normal"
 236        [[bind]]
 237        keys = "SPC m l s"
 238        command = "org.link.store"
 239        mode = "normal"
 240        [[bind]]
 241        keys = "SPC m l i"
 242        command = "org.id.store-link"
 243        mode = "normal"
 244        [[bind]]
 245        keys = "SPC n l"
 246        command = "org.link.store"
 247        mode = "normal"
 248        [[bind]]
 249        keys = "SPC m t"
 250        command = "org.todo.cycle"
 251        mode = "normal"
 252        [[bind]]
 253        keys = "SPC m q"
 254        command = "org.tags.set"
 255        mode = "normal"
 256        [[bind]]
 257        keys = "SPC m x"
 258        command = "org.checkbox.toggle"
 259        mode = "normal"
 260        [[bind]]
 261        keys = "SPC m A"
 262        command = "app.archive"
 263        mode = "normal"
 264        [[bind]]
 265        keys = "SPC m e h h"
 266        command = "app.export.html"
 267        mode = "normal"
 268        [[bind]]
 269        keys = "SPC m e h o"
 270        command = "app.export.html-open"
 271        mode = "normal"
 272        [[bind]]
 273        keys = "SPC m e m m"
 274        command = "app.export.markdown"
 275        mode = "normal"
 276        [[bind]]
 277        keys = "SPC m e l p"
 278        command = "app.export.pdf"
 279        mode = "normal"
 280        [[bind]]
 281        keys = "SPC m d d"
 282        command = "org.deadline"
 283        mode = "normal"
 284        [[bind]]
 285        keys = "SPC m d s"
 286        command = "org.schedule"
 287        mode = "normal"
 288        [[bind]]
 289        keys = "SPC m d t"
 290        command = "org.timestamp.active"
 291        mode = "normal"
 292        [[bind]]
 293        keys = "SPC m d T"
 294        command = "org.timestamp.inactive"
 295        mode = "normal"
 296        [[bind]]
 297        keys = "SPC m r r"
 298        command = "app.refile"
 299        mode = "normal"
 300        [[bind]]
 301        keys = "SPC m s r"
 302        command = "app.refile"
 303        mode = "normal"
 304        [[bind]]
 305        keys = "SPC m s A"
 306        command = "app.archive"
 307        mode = "normal"
 308        [[bind]]
 309        keys = "SPC m s h"
 310        command = "org.subtree.promote"
 311        mode = "normal"
 312        [[bind]]
 313        keys = "SPC m s l"
 314        command = "org.subtree.demote"
 315        mode = "normal"
 316        [[bind]]
 317        keys = "SPC m s j"
 318        command = "org.subtree.down"
 319        mode = "normal"
 320        [[bind]]
 321        keys = "SPC m s k"
 322        command = "org.subtree.up"
 323        mode = "normal"
 324        [[bind]]
 325        keys = "SPC m c i"
 326        command = "app.clock.in"
 327        mode = "normal"
 328        [[bind]]
 329        keys = "SPC m c o"
 330        command = "app.clock.out"
 331        mode = "normal"
 332        [[bind]]
 333        keys = "SPC m c c"
 334        command = "app.clock.cancel"
 335        mode = "normal"
 336        [[bind]]
 337        keys = "SPC m c g"
 338        command = "app.clock.goto"
 339        mode = "normal"
 340        [[bind]]
 341        keys = "SPC m c R"
 342        command = "app.clock.report"
 343        mode = "normal"
 344        [[bind]]
 345        keys = "SPC m c E"
 346        command = "org.effort.set"
 347        mode = "normal"
 348        [[bind]]
 349        keys = "SPC m p u"
 350        command = "org.priority.up"
 351        mode = "normal"
 352        [[bind]]
 353        keys = "SPC m p d"
 354        command = "org.priority.down"
 355        mode = "normal"
 356        [[bind]]
 357        keys = "SPC m b -"
 358        command = "org.table.insert-hline"
 359        mode = "normal"
 360        [[bind]]
 361        keys = "SPC m b a"
 362        command = "org.table.align"
 363        mode = "normal"
 364        [[bind]]
 365        keys = "SPC m b r"
 366        command = "org.table.recalc-all"
 367        mode = "normal"
 368        [[bind]]
 369        keys = "SPC m b d c"
 370        command = "org.table.delete-column"
 371        mode = "normal"
 372        [[bind]]
 373        keys = "SPC m b d r"
 374        command = "org.table.kill-row"
 375        mode = "normal"
 376        [[bind]]
 377        keys = "SPC m b i c"
 378        command = "org.table.insert-column"
 379        mode = "normal"
 380        [[bind]]
 381        keys = "SPC m b i r"
 382        command = "org.table.insert-row"
 383        mode = "normal"
 384        [[bind]]
 385        keys = "SPC m b i h"
 386        command = "org.table.insert-hline"
 387        mode = "normal"
 388
 389        # evil-org and Doom's org keys
 390        [[bind]]
 391        keys = "TAB"
 392        command = "org.cycle"
 393        mode = "normal"
 394        [[bind]]
 395        keys = "S-TAB"
 396        command = "org.cycle-global"
 397        mode = "normal"
 398        [[bind]]
 399        keys = "RET"
 400        command = "org.dwim"
 401        mode = "normal"
 402        [[bind]]
 403        keys = "z a"
 404        command = "org.cycle"
 405        mode = "normal"
 406        [[bind]]
 407        keys = "z c"
 408        command = "org.cycle"
 409        mode = "normal"
 410        [[bind]]
 411        keys = "z o"
 412        command = "org.cycle"
 413        mode = "normal"
 414        [[bind]]
 415        keys = "z A"
 416        command = "org.cycle-global"
 417        mode = "normal"
 418        [[bind]]
 419        keys = "g h"
 420        command = "org.heading.up"
 421        mode = "normal"
 422        [[bind]]
 423        keys = "g j"
 424        command = "org.heading.forward-same-level"
 425        mode = "normal"
 426        [[bind]]
 427        keys = "g k"
 428        command = "org.heading.backward-same-level"
 429        mode = "normal"
 430        [[bind]]
 431        keys = "] h"
 432        command = "org.heading.forward-same-level"
 433        mode = "normal"
 434        [[bind]]
 435        keys = "[ h"
 436        command = "org.heading.backward-same-level"
 437        mode = "normal"
 438        [[bind]]
 439        keys = "RET"
 440        command = "org.table.next-row"
 441        when = "table"
 442        mode = "insert"
 443        [[bind]]
 444        keys = "TAB"
 445        command = "org.cycle"
 446        mode = "visual"
 447        [[bind]]
 448        keys = "S-TAB"
 449        command = "org.cycle-global"
 450        mode = "visual"
 451
 452        # Insert state: org-cycle and org-shifttab with Doom's +org-indent-maybe-h, which
 453        # demotes or promotes a heading and indents or outdents an item tree.
 454        [[bind]]
 455        keys = "S-TAB"
 456        command = "org.cycle-global"
 457        mode = "insert"
 458        [[bind]]
 459        keys = "TAB"
 460        command = "org.table.next-field"
 461        when = "table"
 462        mode = "insert"
 463        [[bind]]
 464        keys = "S-TAB"
 465        command = "org.table.previous-field"
 466        when = "table"
 467        mode = "insert"
 468        [[bind]]
 469        keys = "TAB"
 470        command = "org.item.indent-tree"
 471        when = "item"
 472        mode = "insert"
 473        [[bind]]
 474        keys = "S-TAB"
 475        command = "org.item.outdent-tree"
 476        when = "item"
 477        mode = "insert"
 478        [[bind]]
 479        keys = "TAB"
 480        command = "org.heading.demote"
 481        when = "heading"
 482        mode = "insert"
 483        [[bind]]
 484        keys = "S-TAB"
 485        command = "org.heading.promote"
 486        when = "heading"
 487        mode = "insert"
 488
 489        """
 490
 491
 492    static let common = """
 493        [[bind]]
 494        keys = "TAB"
 495        command = "org.cycle"
 496        when = "heading"
 497        [[bind]]
 498        keys = "TAB"
 499        command = "org.cycle"
 500        when = "fold-line"
 501
 502        [[bind]]
 503        keys = "S-TAB"
 504        command = "org.cycle-global"
 505        [[bind]]
 506        keys = "TAB"
 507        command = "org.table.next-field"
 508        when = "table"
 509        [[bind]]
 510        keys = "S-TAB"
 511        command = "org.table.previous-field"
 512        when = "table"
 513        [[bind]]
 514        keys = "RET"
 515        command = "org.table.next-row"
 516        when = "table"
 517
 518        """
 519
 520    static let emacsBindings = """
 521        # Movement and editing. With a mark set (C-SPC), movement extends the region.
 522        [[bind]]
 523        keys = "C-f"
 524        command = "edit.forward-char"
 525        [[bind]]
 526        keys = "C-b"
 527        command = "edit.backward-char"
 528        [[bind]]
 529        keys = "C-n"
 530        command = "edit.next-line"
 531        [[bind]]
 532        keys = "C-p"
 533        command = "edit.previous-line"
 534        [[bind]]
 535        keys = "C-a"
 536        command = "edit.beginning-of-line"
 537        [[bind]]
 538        keys = "C-e"
 539        command = "edit.end-of-line"
 540        [[bind]]
 541        keys = "M-f"
 542        command = "edit.forward-word"
 543        [[bind]]
 544        keys = "M-b"
 545        command = "edit.backward-word"
 546        [[bind]]
 547        keys = "M-<"
 548        command = "edit.beginning-of-buffer"
 549        [[bind]]
 550        keys = "M->"
 551        command = "edit.end-of-buffer"
 552        [[bind]]
 553        keys = "C-v"
 554        command = "edit.scroll-up"
 555        [[bind]]
 556        keys = "M-v"
 557        command = "edit.scroll-down"
 558        [[bind]]
 559        keys = "C-l"
 560        command = "edit.recenter"
 561        [[bind]]
 562        keys = "C-d"
 563        command = "edit.delete-char"
 564        [[bind]]
 565        keys = "M-d"
 566        command = "edit.kill-word"
 567        [[bind]]
 568        keys = "M-DEL"
 569        command = "edit.backward-kill-word"
 570        [[bind]]
 571        keys = "C-k"
 572        command = "edit.kill-line"
 573        [[bind]]
 574        keys = "C-y"
 575        command = "edit.yank"
 576        [[bind]]
 577        keys = "C-SPC"
 578        command = "edit.set-mark"
 579        [[bind]]
 580        keys = "C-x h"
 581        command = "edit.select-all"
 582        [[bind]]
 583        keys = "C-w"
 584        command = "edit.kill-region"
 585        [[bind]]
 586        keys = "M-w"
 587        command = "edit.copy-region"
 588        [[bind]]
 589        keys = "C-/"
 590        command = "edit.undo"
 591        [[bind]]
 592        keys = "C-_"
 593        command = "edit.undo"
 594        [[bind]]
 595        keys = "C-x u"
 596        command = "edit.undo"
 597        [[bind]]
 598        keys = "C-g"
 599        command = "edit.keyboard-quit"
 600        [[bind]]
 601        keys = "C-t"
 602        command = "edit.transpose-chars"
 603        [[bind]]
 604        keys = "C-s"
 605        command = "edit.find"
 606        [[bind]]
 607        keys = "C-r"
 608        command = "edit.find"
 609        [[bind]]
 610        keys = "M-%"
 611        command = "edit.replace"
 612
 613        # Files and commands
 614        [[bind]]
 615        keys = "C-x C-s"
 616        command = "app.save"
 617        [[bind]]
 618        keys = "C-c C-o"
 619        command = "org.link.open"
 620        [[bind]]
 621        keys = "C-c C-l"
 622        command = "org.link.insert"
 623        [[bind]]
 624        keys = "C-c l"
 625        command = "org.link.store"
 626        [[bind]]
 627        keys = "C-c ;"
 628        command = "org.heading.toggle-comment"
 629        [[bind]]
 630        keys = "C-c *"
 631        command = "org.heading.toggle"
 632        [[bind]]
 633        keys = "C-c -"
 634        command = "org.item.toggle"
 635        [[bind]]
 636        keys = "C-c @"
 637        command = "org.subtree.mark"
 638        [[bind]]
 639        keys = "C-c C-x C-w"
 640        command = "org.subtree.cut"
 641        [[bind]]
 642        keys = "C-c C-x M-w"
 643        command = "org.subtree.copy"
 644        [[bind]]
 645        keys = "C-c C-x C-y"
 646        command = "org.subtree.paste"
 647        [[bind]]
 648        keys = "C-c C-x c"
 649        command = "org.subtree.clone"
 650        [[bind]]
 651        keys = "C-c ^"
 652        command = "org.sort"
 653        [[bind]]
 654        keys = "C-c C-c"
 655        command = "org.ctrl-c-ctrl-c"
 656        [[bind]]
 657        keys = "C-c C-y"
 658        command = "org.timestamp.evaluate-range"
 659        [[bind]]
 660        keys = "C-c C-x f"
 661        command = "org.footnote.action"
 662        [[bind]]
 663        keys = "C-c ="
 664        command = "org.table.column-formula"
 665        [[bind]]
 666        keys = "C-c TAB"
 667        command = "org.table.toggle-column-width"
 668        when = "table"
 669        [[bind]]
 670        keys = "C-x n s"
 671        command = "org.narrow.subtree"
 672        [[bind]]
 673        keys = "C-x n b"
 674        command = "org.narrow.block"
 675        [[bind]]
 676        keys = "C-x n w"
 677        command = "org.widen"
 678        [[bind]]
 679        keys = "C-c C-j"
 680        command = "org.goto"
 681        [[bind]]
 682        keys = "C-c /"
 683        command = "org.sparse-tree"
 684        [[bind]]
 685        keys = "C-c C-x C-r"
 686        command = "org.clock.report"
 687        [[bind]]
 688        keys = "C-c C-x C-u"
 689        command = "org.dblock.update"
 690        [[bind]]
 691        keys = "C-c C-x e"
 692        command = "org.effort.set"
 693        [[bind]]
 694        keys = "C-c C-c"
 695        command = "org.dblock.update"
 696        when = "dblock"
 697        [[bind]]
 698        keys = "C-c C-,"
 699        command = "org.structure-template"
 700        [[bind]]
 701        keys = "C-c '"
 702        command = "org.edit-special"
 703        [[bind]]
 704        keys = "C-x b"
 705        command = "app.buffer.switch"
 706        [[bind]]
 707        keys = "C-x C-b"
 708        command = "app.buffer.switch"
 709        [[bind]]
 710        keys = "C-x k"
 711        command = "app.buffer.kill"
 712        [[bind]]
 713        keys = "C-x <right>"
 714        command = "app.buffer.next"
 715        [[bind]]
 716        keys = "C-x <left>"
 717        command = "app.buffer.previous"
 718        [[bind]]
 719        keys = "C-x s"
 720        command = "app.save-all"
 721        [[bind]]
 722        keys = "C-x C-f"
 723        command = "app.quick-open"
 724        [[bind]]
 725        keys = "M-x"
 726        command = "app.palette"
 727        [[bind]]
 728        keys = "C-c a"
 729        command = "app.agenda"
 730        [[bind]]
 731        keys = "C-c c"
 732        command = "app.capture"
 733        [[bind]]
 734        keys = "C-c C-x C-i"
 735        command = "app.clock.in"
 736        [[bind]]
 737        keys = "C-c C-x C-o"
 738        command = "app.clock.out"
 739        [[bind]]
 740        keys = "C-c C-x C-q"
 741        command = "app.clock.cancel"
 742        [[bind]]
 743        keys = "C-c C-x C-j"
 744        command = "app.clock.goto"
 745        [[bind]]
 746        keys = "C-c C-e h h"
 747        command = "app.export.html"
 748        [[bind]]
 749        keys = "C-c C-e h o"
 750        command = "app.export.html-open"
 751        [[bind]]
 752        keys = "C-c C-e m m"
 753        command = "app.export.markdown"
 754        [[bind]]
 755        keys = "C-c C-e l p"
 756        command = "app.export.pdf"
 757        [[bind]]
 758        keys = "C-c C-e l l"
 759        command = "app.export.latex"
 760        [[bind]]
 761        keys = "C-c C-e o o"
 762        command = "app.export.odt"
 763        [[bind]]
 764        keys = "C-c C-e t u"
 765        command = "app.export.text"
 766
 767        # Org
 768        [[bind]]
 769        keys = "C-c C-t"
 770        command = "org.todo.cycle"
 771        [[bind]]
 772        keys = "S-<right>"
 773        command = "org.todo.next"
 774        when = "heading"
 775        [[bind]]
 776        keys = "S-<left>"
 777        command = "org.todo.previous"
 778        when = "heading"
 779        [[bind]]
 780        keys = "S-<up>"
 781        command = "org.priority.up"
 782        when = "heading"
 783        [[bind]]
 784        keys = "S-<down>"
 785        command = "org.priority.down"
 786        when = "heading"
 787        [[bind]]
 788        keys = "M-<left>"
 789        command = "org.heading.promote"
 790        when = "heading"
 791        [[bind]]
 792        keys = "M-<right>"
 793        command = "org.heading.demote"
 794        when = "heading"
 795        [[bind]]
 796        keys = "M-S-<left>"
 797        command = "org.subtree.promote"
 798        when = "heading"
 799        [[bind]]
 800        keys = "M-S-<right>"
 801        command = "org.subtree.demote"
 802        when = "heading"
 803        [[bind]]
 804        keys = "M-<up>"
 805        command = "org.subtree.up"
 806        when = "heading"
 807        [[bind]]
 808        keys = "M-<down>"
 809        command = "org.subtree.down"
 810        when = "heading"
 811        [[bind]]
 812        keys = "M-RET"
 813        command = "org.heading.insert"
 814        [[bind]]
 815        keys = "C-RET"
 816        command = "org.heading.insert-after-subtree"
 817        [[bind]]
 818        keys = "M-S-RET"
 819        command = "org.heading.insert-todo"
 820        [[bind]]
 821        keys = "C-c C-n"
 822        command = "org.heading.next"
 823        [[bind]]
 824        keys = "C-c C-p"
 825        command = "org.heading.previous"
 826        [[bind]]
 827        keys = "C-c C-f"
 828        command = "org.heading.forward-same-level"
 829        [[bind]]
 830        keys = "C-c C-b"
 831        command = "org.heading.backward-same-level"
 832        [[bind]]
 833        keys = "C-c C-u"
 834        command = "org.heading.up"
 835        [[bind]]
 836        keys = "C-c C-q"
 837        command = "org.tags.set"
 838        [[bind]]
 839        keys = "M-RET"
 840        command = "org.item.insert"
 841        when = "item"
 842        [[bind]]
 843        keys = "M-S-RET"
 844        command = "org.item.insert-checkbox"
 845        when = "item"
 846        [[bind]]
 847        keys = "M-<left>"
 848        command = "org.item.outdent"
 849        when = "item"
 850        [[bind]]
 851        keys = "M-<right>"
 852        command = "org.item.indent"
 853        when = "item"
 854        [[bind]]
 855        keys = "M-S-<left>"
 856        command = "org.item.outdent-tree"
 857        when = "item"
 858        [[bind]]
 859        keys = "M-S-<right>"
 860        command = "org.item.indent-tree"
 861        when = "item"
 862        [[bind]]
 863        keys = "M-<up>"
 864        command = "org.item.up"
 865        when = "item"
 866        [[bind]]
 867        keys = "M-<down>"
 868        command = "org.item.down"
 869        when = "item"
 870        [[bind]]
 871        keys = "C-c C-c"
 872        command = "org.ctrl-c-ctrl-c"
 873        when = "item"
 874        [[bind]]
 875        keys = "C-c C-x C-b"
 876        command = "org.checkbox.toggle"
 877        [[bind]]
 878        keys = "C-c C-w"
 879        command = "app.refile"
 880        [[bind]]
 881        keys = "C-c C-x C-s"
 882        command = "app.archive"
 883        [[bind]]
 884        keys = "C-c $"
 885        command = "app.archive"
 886        [[bind]]
 887        keys = "C-c ."
 888        command = "org.timestamp.active"
 889        [[bind]]
 890        keys = "C-c !"
 891        command = "org.timestamp.inactive"
 892        [[bind]]
 893        keys = "C-c C-s"
 894        command = "org.schedule"
 895        [[bind]]
 896        keys = "C-c C-d"
 897        command = "org.deadline"
 898        [[bind]]
 899        keys = "M-q"
 900        command = "org.fill-paragraph"
 901        [[bind]]
 902        keys = "C-c C-c"
 903        command = "org.table.align"
 904        when = "table"
 905        [[bind]]
 906        keys = "C-c C-c"
 907        command = "org.table.recalc-all"
 908        when = "tblfm"
 909        [[bind]]
 910        keys = "C-c *"
 911        command = "org.table.recalc"
 912        when = "table"
 913        [[bind]]
 914        keys = "C-c C-c"
 915        command = "org.babel.execute"
 916        when = "src"
 917        [[bind]]
 918        keys = "M-<up>"
 919        command = "org.table.row-up"
 920        when = "table"
 921        [[bind]]
 922        keys = "M-<down>"
 923        command = "org.table.row-down"
 924        when = "table"
 925        [[bind]]
 926        keys = "M-<left>"
 927        command = "org.table.column-left"
 928        when = "table"
 929        [[bind]]
 930        keys = "M-<right>"
 931        command = "org.table.column-right"
 932        when = "table"
 933        [[bind]]
 934        keys = "M-S-<right>"
 935        command = "org.table.insert-column"
 936        when = "table"
 937        [[bind]]
 938        keys = "M-S-<left>"
 939        command = "org.table.delete-column"
 940        when = "table"
 941        [[bind]]
 942        keys = "M-S-<up>"
 943        command = "org.table.kill-row"
 944        when = "table"
 945        [[bind]]
 946        keys = "M-S-<down>"
 947        command = "org.table.insert-row"
 948        when = "table"
 949        [[bind]]
 950        keys = "C-c -"
 951        command = "org.table.insert-hline"
 952        when = "table"
 953        [[bind]]
 954        keys = "C-c |"
 955        command = "org.table.create"
 956        [[bind]]
 957        keys = "S-<up>"
 958        command = "org.timestamp.up"
 959        when = "timestamp"
 960        [[bind]]
 961        keys = "S-<down>"
 962        command = "org.timestamp.down"
 963        when = "timestamp"
 964        [[bind]]
 965        keys = "S-<right>"
 966        command = "org.timestamp.day-later"
 967        when = "timestamp"
 968        [[bind]]
 969        keys = "S-<left>"
 970        command = "org.timestamp.day-earlier"
 971        when = "timestamp"
 972
 973        """
 974
 975    /// Standard Mac text keys stay as they are; org commands use Control-Command chords, which
 976    /// macOS text editing leaves free.
 977    static let macBindings = """
 978        [[bind]]
 979        keys = "C-TAB"
 980        command = "app.buffer.next"
 981        [[bind]]
 982        keys = "C-S-TAB"
 983        command = "app.buffer.previous"
 984        [[bind]]
 985        keys = "C-s-t"
 986        command = "org.todo.cycle"
 987        [[bind]]
 988        keys = "C-s-<up>"
 989        command = "org.priority.up"
 990        [[bind]]
 991        keys = "C-s-<down>"
 992        command = "org.priority.down"
 993        [[bind]]
 994        keys = "C-s-<left>"
 995        command = "org.heading.promote"
 996        [[bind]]
 997        keys = "C-s-<right>"
 998        command = "org.heading.demote"
 999        [[bind]]
1000        keys = "C-M-s-<left>"
1001        command = "org.subtree.promote"
1002        [[bind]]
1003        keys = "C-M-s-<right>"
1004        command = "org.subtree.demote"
1005        [[bind]]
1006        keys = "C-M-s-<up>"
1007        command = "org.subtree.up"
1008        [[bind]]
1009        keys = "C-M-s-<down>"
1010        command = "org.subtree.down"
1011        [[bind]]
1012        keys = "s-RET"
1013        command = "org.heading.insert"
1014        [[bind]]
1015        keys = "C-s-RET"
1016        command = "org.heading.insert-after-subtree"
1017        [[bind]]
1018        keys = "s-S-RET"
1019        command = "org.heading.insert-todo"
1020        [[bind]]
1021        keys = "M-s-<down>"
1022        command = "org.heading.next"
1023        [[bind]]
1024        keys = "M-s-<up>"
1025        command = "org.heading.previous"
1026        [[bind]]
1027        keys = "C-s-q"
1028        command = "org.tags.set"
1029        [[bind]]
1030        keys = "s-RET"
1031        command = "org.item.insert"
1032        when = "item"
1033        [[bind]]
1034        keys = "s-S-RET"
1035        command = "org.item.insert-checkbox"
1036        when = "item"
1037        [[bind]]
1038        keys = "C-s-<left>"
1039        command = "org.item.outdent"
1040        when = "item"
1041        [[bind]]
1042        keys = "C-s-<right>"
1043        command = "org.item.indent"
1044        when = "item"
1045        [[bind]]
1046        keys = "C-M-s-<left>"
1047        command = "org.item.outdent-tree"
1048        when = "item"
1049        [[bind]]
1050        keys = "C-M-s-<right>"
1051        command = "org.item.indent-tree"
1052        when = "item"
1053        [[bind]]
1054        keys = "C-M-s-<up>"
1055        command = "org.item.up"
1056        when = "item"
1057        [[bind]]
1058        keys = "C-M-s-<down>"
1059        command = "org.item.down"
1060        when = "item"
1061        [[bind]]
1062        keys = "C-s-c"
1063        command = "org.checkbox.toggle"
1064        [[bind]]
1065        keys = "C-s-w"
1066        command = "app.refile"
1067        [[bind]]
1068        keys = "C-s-a"
1069        command = "app.archive"
1070        [[bind]]
1071        keys = "C-s-."
1072        command = "org.timestamp.active"
1073        [[bind]]
1074        keys = "C-M-s-."
1075        command = "org.timestamp.inactive"
1076        [[bind]]
1077        keys = "C-s-s"
1078        command = "org.schedule"
1079        [[bind]]
1080        keys = "C-s-d"
1081        command = "org.deadline"
1082        [[bind]]
1083        keys = "C-s-p"
1084        command = "org.fill-paragraph"
1085        [[bind]]
1086        keys = "C-s-<up>"
1087        command = "org.table.row-up"
1088        when = "table"
1089        [[bind]]
1090        keys = "C-s-<down>"
1091        command = "org.table.row-down"
1092        when = "table"
1093        [[bind]]
1094        keys = "C-s-<left>"
1095        command = "org.table.column-left"
1096        when = "table"
1097        [[bind]]
1098        keys = "C-s-<right>"
1099        command = "org.table.column-right"
1100        when = "table"
1101        [[bind]]
1102        keys = "C-M-s-<right>"
1103        command = "org.table.insert-column"
1104        when = "table"
1105        [[bind]]
1106        keys = "C-M-s-<left>"
1107        command = "org.table.delete-column"
1108        when = "table"
1109        [[bind]]
1110        keys = "C-M-s-<up>"
1111        command = "org.table.kill-row"
1112        when = "table"
1113        [[bind]]
1114        keys = "C-M-s-<down>"
1115        command = "org.table.insert-row"
1116        when = "table"
1117        [[bind]]
1118        keys = "C-s--"
1119        command = "org.table.insert-hline"
1120        when = "table"
1121        [[bind]]
1122        keys = "C-s-\\\\"
1123        command = "org.table.create"
1124        [[bind]]
1125        keys = "C-s-<up>"
1126        command = "org.timestamp.up"
1127        when = "timestamp"
1128        [[bind]]
1129        keys = "C-s-<down>"
1130        command = "org.timestamp.down"
1131        when = "timestamp"
1132        [[bind]]
1133        keys = "C-s-<right>"
1134        command = "org.timestamp.day-later"
1135        when = "timestamp"
1136        [[bind]]
1137        keys = "C-s-<left>"
1138        command = "org.timestamp.day-earlier"
1139        when = "timestamp"
1140
1141        """
1142}