Sources/OrgCore/Keymap/Presets.swift

62fdf490e1b4bd89900f188ea9cb58718e52d75b
orgstar/Sources/OrgCore/Keymap/Presets.swift history · blame · raw

1021 lines · 28192 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        [[bind]]
 454        keys = "TAB"
 455        command = "org.cycle"
 456        when = "fold-line"
 457
 458        [[bind]]
 459        keys = "S-TAB"
 460        command = "org.cycle-global"
 461        [[bind]]
 462        keys = "TAB"
 463        command = "org.table.next-field"
 464        when = "table"
 465        [[bind]]
 466        keys = "S-TAB"
 467        command = "org.table.previous-field"
 468        when = "table"
 469        [[bind]]
 470        keys = "RET"
 471        command = "org.table.next-row"
 472        when = "table"
 473
 474        """
 475
 476    static let emacsBindings = """
 477        # Movement and editing. With a mark set (C-SPC), movement extends the region.
 478        [[bind]]
 479        keys = "C-f"
 480        command = "edit.forward-char"
 481        [[bind]]
 482        keys = "C-b"
 483        command = "edit.backward-char"
 484        [[bind]]
 485        keys = "C-n"
 486        command = "edit.next-line"
 487        [[bind]]
 488        keys = "C-p"
 489        command = "edit.previous-line"
 490        [[bind]]
 491        keys = "C-a"
 492        command = "edit.beginning-of-line"
 493        [[bind]]
 494        keys = "C-e"
 495        command = "edit.end-of-line"
 496        [[bind]]
 497        keys = "M-f"
 498        command = "edit.forward-word"
 499        [[bind]]
 500        keys = "M-b"
 501        command = "edit.backward-word"
 502        [[bind]]
 503        keys = "M-<"
 504        command = "edit.beginning-of-buffer"
 505        [[bind]]
 506        keys = "M->"
 507        command = "edit.end-of-buffer"
 508        [[bind]]
 509        keys = "C-v"
 510        command = "edit.scroll-up"
 511        [[bind]]
 512        keys = "M-v"
 513        command = "edit.scroll-down"
 514        [[bind]]
 515        keys = "C-l"
 516        command = "edit.recenter"
 517        [[bind]]
 518        keys = "C-d"
 519        command = "edit.delete-char"
 520        [[bind]]
 521        keys = "M-d"
 522        command = "edit.kill-word"
 523        [[bind]]
 524        keys = "M-DEL"
 525        command = "edit.backward-kill-word"
 526        [[bind]]
 527        keys = "C-k"
 528        command = "edit.kill-line"
 529        [[bind]]
 530        keys = "C-y"
 531        command = "edit.yank"
 532        [[bind]]
 533        keys = "C-SPC"
 534        command = "edit.set-mark"
 535        [[bind]]
 536        keys = "C-x h"
 537        command = "edit.select-all"
 538        [[bind]]
 539        keys = "C-w"
 540        command = "edit.kill-region"
 541        [[bind]]
 542        keys = "M-w"
 543        command = "edit.copy-region"
 544        [[bind]]
 545        keys = "C-/"
 546        command = "edit.undo"
 547        [[bind]]
 548        keys = "C-_"
 549        command = "edit.undo"
 550        [[bind]]
 551        keys = "C-x u"
 552        command = "edit.undo"
 553        [[bind]]
 554        keys = "C-g"
 555        command = "edit.keyboard-quit"
 556        [[bind]]
 557        keys = "C-t"
 558        command = "edit.transpose-chars"
 559        [[bind]]
 560        keys = "C-s"
 561        command = "edit.find"
 562        [[bind]]
 563        keys = "C-r"
 564        command = "edit.find"
 565        [[bind]]
 566        keys = "M-%"
 567        command = "edit.replace"
 568
 569        # Files and commands
 570        [[bind]]
 571        keys = "C-x C-s"
 572        command = "app.save"
 573        [[bind]]
 574        keys = "C-c C-o"
 575        command = "org.link.open"
 576        [[bind]]
 577        keys = "C-c C-l"
 578        command = "org.link.insert"
 579        [[bind]]
 580        keys = "C-c l"
 581        command = "org.link.store"
 582        [[bind]]
 583        keys = "C-x b"
 584        command = "app.buffer.switch"
 585        [[bind]]
 586        keys = "C-x C-b"
 587        command = "app.buffer.switch"
 588        [[bind]]
 589        keys = "C-x k"
 590        command = "app.buffer.kill"
 591        [[bind]]
 592        keys = "C-x <right>"
 593        command = "app.buffer.next"
 594        [[bind]]
 595        keys = "C-x <left>"
 596        command = "app.buffer.previous"
 597        [[bind]]
 598        keys = "C-x s"
 599        command = "app.save-all"
 600        [[bind]]
 601        keys = "C-x C-f"
 602        command = "app.quick-open"
 603        [[bind]]
 604        keys = "M-x"
 605        command = "app.palette"
 606        [[bind]]
 607        keys = "C-c a"
 608        command = "app.agenda"
 609        [[bind]]
 610        keys = "C-c c"
 611        command = "app.capture"
 612        [[bind]]
 613        keys = "C-c C-x C-i"
 614        command = "app.clock.in"
 615        [[bind]]
 616        keys = "C-c C-x C-o"
 617        command = "app.clock.out"
 618        [[bind]]
 619        keys = "C-c C-x C-q"
 620        command = "app.clock.cancel"
 621        [[bind]]
 622        keys = "C-c C-x C-j"
 623        command = "app.clock.goto"
 624        [[bind]]
 625        keys = "C-c C-e h h"
 626        command = "app.export.html"
 627        [[bind]]
 628        keys = "C-c C-e h o"
 629        command = "app.export.html-open"
 630        [[bind]]
 631        keys = "C-c C-e m m"
 632        command = "app.export.markdown"
 633        [[bind]]
 634        keys = "C-c C-e l p"
 635        command = "app.export.pdf"
 636        [[bind]]
 637        keys = "C-c C-e l l"
 638        command = "app.export.latex"
 639        [[bind]]
 640        keys = "C-c C-e o o"
 641        command = "app.export.odt"
 642        [[bind]]
 643        keys = "C-c C-e t u"
 644        command = "app.export.text"
 645
 646        # Org
 647        [[bind]]
 648        keys = "C-c C-t"
 649        command = "org.todo.cycle"
 650        [[bind]]
 651        keys = "S-<right>"
 652        command = "org.todo.next"
 653        when = "heading"
 654        [[bind]]
 655        keys = "S-<left>"
 656        command = "org.todo.previous"
 657        when = "heading"
 658        [[bind]]
 659        keys = "S-<up>"
 660        command = "org.priority.up"
 661        when = "heading"
 662        [[bind]]
 663        keys = "S-<down>"
 664        command = "org.priority.down"
 665        when = "heading"
 666        [[bind]]
 667        keys = "M-<left>"
 668        command = "org.heading.promote"
 669        when = "heading"
 670        [[bind]]
 671        keys = "M-<right>"
 672        command = "org.heading.demote"
 673        when = "heading"
 674        [[bind]]
 675        keys = "M-S-<left>"
 676        command = "org.subtree.promote"
 677        when = "heading"
 678        [[bind]]
 679        keys = "M-S-<right>"
 680        command = "org.subtree.demote"
 681        when = "heading"
 682        [[bind]]
 683        keys = "M-<up>"
 684        command = "org.subtree.up"
 685        when = "heading"
 686        [[bind]]
 687        keys = "M-<down>"
 688        command = "org.subtree.down"
 689        when = "heading"
 690        [[bind]]
 691        keys = "M-RET"
 692        command = "org.heading.insert"
 693        [[bind]]
 694        keys = "C-RET"
 695        command = "org.heading.insert-after-subtree"
 696        [[bind]]
 697        keys = "M-S-RET"
 698        command = "org.heading.insert-todo"
 699        [[bind]]
 700        keys = "C-c C-n"
 701        command = "org.heading.next"
 702        [[bind]]
 703        keys = "C-c C-p"
 704        command = "org.heading.previous"
 705        [[bind]]
 706        keys = "C-c C-f"
 707        command = "org.heading.forward-same-level"
 708        [[bind]]
 709        keys = "C-c C-b"
 710        command = "org.heading.backward-same-level"
 711        [[bind]]
 712        keys = "C-c C-u"
 713        command = "org.heading.up"
 714        [[bind]]
 715        keys = "C-c C-q"
 716        command = "org.tags.set"
 717        [[bind]]
 718        keys = "M-RET"
 719        command = "org.item.insert"
 720        when = "item"
 721        [[bind]]
 722        keys = "M-S-RET"
 723        command = "org.item.insert-checkbox"
 724        when = "item"
 725        [[bind]]
 726        keys = "M-<left>"
 727        command = "org.item.outdent"
 728        when = "item"
 729        [[bind]]
 730        keys = "M-<right>"
 731        command = "org.item.indent"
 732        when = "item"
 733        [[bind]]
 734        keys = "M-S-<left>"
 735        command = "org.item.outdent-tree"
 736        when = "item"
 737        [[bind]]
 738        keys = "M-S-<right>"
 739        command = "org.item.indent-tree"
 740        when = "item"
 741        [[bind]]
 742        keys = "M-<up>"
 743        command = "org.item.up"
 744        when = "item"
 745        [[bind]]
 746        keys = "M-<down>"
 747        command = "org.item.down"
 748        when = "item"
 749        [[bind]]
 750        keys = "C-c C-c"
 751        command = "org.checkbox.toggle"
 752        when = "item"
 753        [[bind]]
 754        keys = "C-c C-x C-b"
 755        command = "org.checkbox.toggle"
 756        [[bind]]
 757        keys = "C-c C-w"
 758        command = "app.refile"
 759        [[bind]]
 760        keys = "C-c C-x C-s"
 761        command = "app.archive"
 762        [[bind]]
 763        keys = "C-c $"
 764        command = "app.archive"
 765        [[bind]]
 766        keys = "C-c ."
 767        command = "org.timestamp.active"
 768        [[bind]]
 769        keys = "C-c !"
 770        command = "org.timestamp.inactive"
 771        [[bind]]
 772        keys = "C-c C-s"
 773        command = "org.schedule"
 774        [[bind]]
 775        keys = "C-c C-d"
 776        command = "org.deadline"
 777        [[bind]]
 778        keys = "M-q"
 779        command = "org.fill-paragraph"
 780        [[bind]]
 781        keys = "C-c C-c"
 782        command = "org.table.align"
 783        when = "table"
 784        [[bind]]
 785        keys = "C-c C-c"
 786        command = "org.table.recalc-all"
 787        when = "tblfm"
 788        [[bind]]
 789        keys = "C-c *"
 790        command = "org.table.recalc"
 791        when = "table"
 792        [[bind]]
 793        keys = "C-c C-c"
 794        command = "org.babel.execute"
 795        when = "src"
 796        [[bind]]
 797        keys = "M-<up>"
 798        command = "org.table.row-up"
 799        when = "table"
 800        [[bind]]
 801        keys = "M-<down>"
 802        command = "org.table.row-down"
 803        when = "table"
 804        [[bind]]
 805        keys = "M-<left>"
 806        command = "org.table.column-left"
 807        when = "table"
 808        [[bind]]
 809        keys = "M-<right>"
 810        command = "org.table.column-right"
 811        when = "table"
 812        [[bind]]
 813        keys = "M-S-<right>"
 814        command = "org.table.insert-column"
 815        when = "table"
 816        [[bind]]
 817        keys = "M-S-<left>"
 818        command = "org.table.delete-column"
 819        when = "table"
 820        [[bind]]
 821        keys = "M-S-<up>"
 822        command = "org.table.kill-row"
 823        when = "table"
 824        [[bind]]
 825        keys = "M-S-<down>"
 826        command = "org.table.insert-row"
 827        when = "table"
 828        [[bind]]
 829        keys = "C-c -"
 830        command = "org.table.insert-hline"
 831        when = "table"
 832        [[bind]]
 833        keys = "C-c |"
 834        command = "org.table.create"
 835        [[bind]]
 836        keys = "S-<up>"
 837        command = "org.timestamp.up"
 838        when = "timestamp"
 839        [[bind]]
 840        keys = "S-<down>"
 841        command = "org.timestamp.down"
 842        when = "timestamp"
 843        [[bind]]
 844        keys = "S-<right>"
 845        command = "org.timestamp.day-later"
 846        when = "timestamp"
 847        [[bind]]
 848        keys = "S-<left>"
 849        command = "org.timestamp.day-earlier"
 850        when = "timestamp"
 851
 852        """
 853
 854    /// Standard Mac text keys stay as they are; org commands use Control-Command chords, which
 855    /// macOS text editing leaves free.
 856    static let macBindings = """
 857        [[bind]]
 858        keys = "C-TAB"
 859        command = "app.buffer.next"
 860        [[bind]]
 861        keys = "C-S-TAB"
 862        command = "app.buffer.previous"
 863        [[bind]]
 864        keys = "C-s-t"
 865        command = "org.todo.cycle"
 866        [[bind]]
 867        keys = "C-s-<up>"
 868        command = "org.priority.up"
 869        [[bind]]
 870        keys = "C-s-<down>"
 871        command = "org.priority.down"
 872        [[bind]]
 873        keys = "C-s-<left>"
 874        command = "org.heading.promote"
 875        [[bind]]
 876        keys = "C-s-<right>"
 877        command = "org.heading.demote"
 878        [[bind]]
 879        keys = "C-M-s-<left>"
 880        command = "org.subtree.promote"
 881        [[bind]]
 882        keys = "C-M-s-<right>"
 883        command = "org.subtree.demote"
 884        [[bind]]
 885        keys = "C-M-s-<up>"
 886        command = "org.subtree.up"
 887        [[bind]]
 888        keys = "C-M-s-<down>"
 889        command = "org.subtree.down"
 890        [[bind]]
 891        keys = "s-RET"
 892        command = "org.heading.insert"
 893        [[bind]]
 894        keys = "C-s-RET"
 895        command = "org.heading.insert-after-subtree"
 896        [[bind]]
 897        keys = "s-S-RET"
 898        command = "org.heading.insert-todo"
 899        [[bind]]
 900        keys = "M-s-<down>"
 901        command = "org.heading.next"
 902        [[bind]]
 903        keys = "M-s-<up>"
 904        command = "org.heading.previous"
 905        [[bind]]
 906        keys = "C-s-q"
 907        command = "org.tags.set"
 908        [[bind]]
 909        keys = "s-RET"
 910        command = "org.item.insert"
 911        when = "item"
 912        [[bind]]
 913        keys = "s-S-RET"
 914        command = "org.item.insert-checkbox"
 915        when = "item"
 916        [[bind]]
 917        keys = "C-s-<left>"
 918        command = "org.item.outdent"
 919        when = "item"
 920        [[bind]]
 921        keys = "C-s-<right>"
 922        command = "org.item.indent"
 923        when = "item"
 924        [[bind]]
 925        keys = "C-M-s-<left>"
 926        command = "org.item.outdent-tree"
 927        when = "item"
 928        [[bind]]
 929        keys = "C-M-s-<right>"
 930        command = "org.item.indent-tree"
 931        when = "item"
 932        [[bind]]
 933        keys = "C-M-s-<up>"
 934        command = "org.item.up"
 935        when = "item"
 936        [[bind]]
 937        keys = "C-M-s-<down>"
 938        command = "org.item.down"
 939        when = "item"
 940        [[bind]]
 941        keys = "C-s-c"
 942        command = "org.checkbox.toggle"
 943        [[bind]]
 944        keys = "C-s-w"
 945        command = "app.refile"
 946        [[bind]]
 947        keys = "C-s-a"
 948        command = "app.archive"
 949        [[bind]]
 950        keys = "C-s-."
 951        command = "org.timestamp.active"
 952        [[bind]]
 953        keys = "C-M-s-."
 954        command = "org.timestamp.inactive"
 955        [[bind]]
 956        keys = "C-s-s"
 957        command = "org.schedule"
 958        [[bind]]
 959        keys = "C-s-d"
 960        command = "org.deadline"
 961        [[bind]]
 962        keys = "C-s-p"
 963        command = "org.fill-paragraph"
 964        [[bind]]
 965        keys = "C-s-<up>"
 966        command = "org.table.row-up"
 967        when = "table"
 968        [[bind]]
 969        keys = "C-s-<down>"
 970        command = "org.table.row-down"
 971        when = "table"
 972        [[bind]]
 973        keys = "C-s-<left>"
 974        command = "org.table.column-left"
 975        when = "table"
 976        [[bind]]
 977        keys = "C-s-<right>"
 978        command = "org.table.column-right"
 979        when = "table"
 980        [[bind]]
 981        keys = "C-M-s-<right>"
 982        command = "org.table.insert-column"
 983        when = "table"
 984        [[bind]]
 985        keys = "C-M-s-<left>"
 986        command = "org.table.delete-column"
 987        when = "table"
 988        [[bind]]
 989        keys = "C-M-s-<up>"
 990        command = "org.table.kill-row"
 991        when = "table"
 992        [[bind]]
 993        keys = "C-M-s-<down>"
 994        command = "org.table.insert-row"
 995        when = "table"
 996        [[bind]]
 997        keys = "C-s--"
 998        command = "org.table.insert-hline"
 999        when = "table"
1000        [[bind]]
1001        keys = "C-s-\\\\"
1002        command = "org.table.create"
1003        [[bind]]
1004        keys = "C-s-<up>"
1005        command = "org.timestamp.up"
1006        when = "timestamp"
1007        [[bind]]
1008        keys = "C-s-<down>"
1009        command = "org.timestamp.down"
1010        when = "timestamp"
1011        [[bind]]
1012        keys = "C-s-<right>"
1013        command = "org.timestamp.day-later"
1014        when = "timestamp"
1015        [[bind]]
1016        keys = "C-s-<left>"
1017        command = "org.timestamp.day-earlier"
1018        when = "timestamp"
1019
1020        """
1021}