Sources/OrgCore/Keymap/Presets.swift

9abba9cfc504b344b7d267978a97f1c925a1d5dd
orgstar/Sources/OrgCore/Keymap/Presets.swift history · blame · raw

1240 lines · 35113 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.speedBindings(mode: nil) + Self.emacsBindings
  26        case .mac: Self.common + Self.speedBindings(mode: nil) + Self.macBindings
  27        case .doom: Self.doomToml + Self.speedBindings(mode: "insert")
  28        }
  29    }
  30
  31    /// `org-speed-commands`, for the start of a heading line when `org-use-speed-commands` is on.
  32    static let speedCommands: [(key: String, command: String)] = [
  33        ("n", "org.heading.next"), ("p", "org.heading.previous"), ("f", "org.heading.forward-same-level"),
  34        ("b", "org.heading.backward-same-level"), ("u", "org.heading.up"), ("j", "org.goto"),
  35        ("c", "org.cycle"), ("C", "org.cycle-global"), ("s", "org.narrow.toggle"), ("k", "org.subtree.cut"),
  36        ("U", "org.subtree.up"), ("D", "org.subtree.down"), ("r", "org.heading.demote"), ("l", "org.heading.promote"),
  37        ("R", "org.subtree.demote"), ("L", "org.subtree.promote"), ("i", "org.heading.insert-after-subtree"),
  38        ("^", "org.sort"), ("w", "app.refile"), ("a", "app.archive"), ("@", "org.subtree.mark"),
  39        ("#", "org.heading.toggle-comment"), ("I", "app.clock.in"), ("O", "app.clock.out"), ("t", "org.todo.cycle"),
  40        (",", "org.priority.set"), ("0", "org.priority.remove"), ("1", "org.priority.set-a"), ("2", "org.priority.set-b"),
  41        ("3", "org.priority.set-c"), (":", "org.tags.set"), ("e", "org.effort.set"), ("v", "app.agenda"),
  42        ("/", "org.sparse-tree"), ("o", "org.link.open"),
  43    ]
  44
  45    static func speedBindings(mode: String?) -> String {
  46        speedCommands.map { key, command in
  47            "[[bind]]\nkeys = \"\(key)\"\ncommand = \"\(command)\"\nwhen = \"speed\"\n" + (mode.map { "mode = \"\($0)\"\n" } ?? "")
  48        }.joined()
  49    }
  50
  51    /// Doom: the Emacs preset's org bindings in every evil state (as org-mode-map's are), with
  52    /// evil-org's `M-h/j/k/l` forms, then Doom's leader, localleader and evil-org keys.
  53    static var doomToml: String {
  54        var problems: [String] = []
  55        let emacs = try! Keymap(toml: common + emacsBindings, problems: &problems)
  56        let translations: [String: String] = ["<left>": "h", "<right>": "l", "<up>": "k", "<down>": "j"]
  57        var out = ""
  58        func bind(_ keys: String, _ command: String, when: String?, mode: String) {
  59            out += "[[bind]]\nkeys = \"\(keys.replacingOccurrences(of: "\\", with: "\\\\"))\"\ncommand = \"\(command)\"\n"
  60            if let when { out += "when = \"\(when)\"\n" }
  61            out += "mode = \"\(mode)\"\n"
  62        }
  63        for binding in emacs.bindings {
  64            let first = binding.keys[0]
  65            let keys = KeySequence.format(binding.keys)
  66            let orgKey = first.key == "c" && first.modifiers == [.control] || first.key == "x" && first.modifiers == [.control]
  67                || (first.modifiers.contains(.meta) && ["<left>", "<right>", "<up>", "<down>", "RET"].contains(first.key))
  68                || (first.modifiers.contains(.shift) && ["<left>", "<right>", "<up>", "<down>"].contains(first.key))
  69                || (first.modifiers == [.control] && first.key == "RET")
  70                || keys == "M-x"
  71            guard orgKey else { continue }
  72            for mode in ["normal", "insert", "visual"] { bind(keys, binding.command, when: binding.when, mode: mode) }
  73            // evil-org: M-h/j/k/l and M-H/J/K/L in normal, visual and insert.
  74            if binding.keys.count == 1, first.modifiers.contains(.meta), let letter = translations[first.key] {
  75                let shifted = first.modifiers.contains(.shift)
  76                let key = "M-" + (shifted ? letter.uppercased() : letter)
  77                for mode in ["normal", "insert", "visual"] { bind(key, binding.command, when: binding.when, mode: mode) }
  78            }
  79            // Doom: C-S-h/j/k/l are org-shift* in normal and insert.
  80            if binding.keys.count == 1, first.modifiers == [.shift], let letter = translations[first.key] {
  81                for mode in ["normal", "insert"] { bind("C-" + letter.uppercased(), binding.command, when: binding.when, mode: mode) }
  82            }
  83            // evil-org insert state: C-t demotes, C-d promotes.
  84            if binding.keys.count == 1, first.modifiers == [.meta], first.key == "<right>" || first.key == "<left>" {
  85                bind(first.key == "<right>" ? "C-t" : "C-d", binding.command, when: binding.when, mode: "insert")
  86            }
  87        }
  88        return out + doomBindings
  89    }
  90
  91    static let doomBindings = """
  92        # Leader
  93        [[bind]]
  94        keys = "SPC SPC"
  95        command = "app.quick-open"
  96        mode = "normal"
  97        [[bind]]
  98        keys = "SPC q q"
  99        command = "app.quit"
 100        mode = "normal"
 101        [[bind]]
 102        keys = "SPC ."
 103        command = "app.quick-open"
 104        mode = "normal"
 105        [[bind]]
 106        keys = "SPC f f"
 107        command = "app.quick-open"
 108        mode = "normal"
 109        [[bind]]
 110        keys = "SPC f s"
 111        command = "app.save"
 112        mode = "normal"
 113        # Buffers
 114        [[bind]]
 115        keys = "SPC b b"
 116        command = "app.buffer.switch"
 117        mode = "normal"
 118        [[bind]]
 119        keys = "SPC b B"
 120        command = "app.buffer.switch"
 121        mode = "normal"
 122        [[bind]]
 123        keys = "SPC ,"
 124        command = "app.buffer.switch"
 125        mode = "normal"
 126        [[bind]]
 127        keys = "SPC `"
 128        command = "app.buffer.last"
 129        mode = "normal"
 130        [[bind]]
 131        keys = "SPC b k"
 132        command = "app.buffer.kill"
 133        mode = "normal"
 134        [[bind]]
 135        keys = "SPC b d"
 136        command = "app.buffer.kill"
 137        mode = "normal"
 138        [[bind]]
 139        keys = "SPC b K"
 140        command = "app.buffer.kill-all"
 141        mode = "normal"
 142        [[bind]]
 143        keys = "SPC b O"
 144        command = "app.buffer.kill-others"
 145        mode = "normal"
 146        [[bind]]
 147        keys = "SPC b n"
 148        command = "app.buffer.next"
 149        mode = "normal"
 150        [[bind]]
 151        keys = "SPC b p"
 152        command = "app.buffer.previous"
 153        mode = "normal"
 154        [[bind]]
 155        keys = "SPC b ]"
 156        command = "app.buffer.next"
 157        mode = "normal"
 158        [[bind]]
 159        keys = "SPC b ["
 160        command = "app.buffer.previous"
 161        mode = "normal"
 162        [[bind]]
 163        keys = "] b"
 164        command = "app.buffer.next"
 165        mode = "normal"
 166        [[bind]]
 167        keys = "[ b"
 168        command = "app.buffer.previous"
 169        mode = "normal"
 170        [[bind]]
 171        keys = "SPC b s"
 172        command = "app.save"
 173        mode = "normal"
 174        [[bind]]
 175        keys = "SPC b S"
 176        command = "app.save-all"
 177        mode = "normal"
 178        [[bind]]
 179        keys = "SPC s s"
 180        command = "edit.find"
 181        mode = "normal"
 182        [[bind]]
 183        keys = "SPC /"
 184        command = "app.search"
 185        mode = "normal"
 186        [[bind]]
 187        keys = "SPC s p"
 188        command = "app.search"
 189        mode = "normal"
 190        [[bind]]
 191        keys = "SPC :"
 192        command = "app.palette"
 193        mode = "normal"
 194        [[bind]]
 195        keys = "SPC o a"
 196        command = "app.agenda"
 197        mode = "normal"
 198        [[bind]]
 199        keys = "SPC X"
 200        command = "app.capture"
 201        mode = "normal"
 202        [[bind]]
 203        keys = "SPC z t"
 204        command = "app.clock.report"
 205        mode = "normal"
 206        [[bind]]
 207        keys = "SPC h r r"
 208        command = "app.reload-keymap"
 209        mode = "normal"
 210        [[bind]]
 211        keys = "SPC t s"
 212        command = "editor.toggle-spell-check"
 213        mode = "normal"
 214        [[bind]]
 215        keys = "SPC t w"
 216        command = "editor.toggle-truncate-lines"
 217        mode = "normal"
 218
 219        # Localleader (SPC m)
 220        [[bind]]
 221        keys = "SPC m '"
 222        command = "org.edit-special"
 223        mode = "normal"
 224        [[bind]]
 225        keys = "SPC m s c"
 226        command = "org.subtree.clone"
 227        mode = "normal"
 228        [[bind]]
 229        keys = "SPC m s d"
 230        command = "org.subtree.cut"
 231        mode = "normal"
 232        [[bind]]
 233        keys = "SPC m s S"
 234        command = "org.sort"
 235        mode = "normal"
 236        [[bind]]
 237        keys = "SPC m s n"
 238        command = "org.narrow.subtree"
 239        mode = "normal"
 240        [[bind]]
 241        keys = "SPC m s s"
 242        command = "org.sparse-tree"
 243        mode = "normal"
 244        [[bind]]
 245        keys = "SPC m s N"
 246        command = "org.widen"
 247        mode = "normal"
 248        [[bind]]
 249        keys = "SPC m ."
 250        command = "org.goto"
 251        mode = "normal"
 252        [[bind]]
 253        keys = "SPC m h"
 254        command = "org.heading.toggle"
 255        mode = "normal"
 256        [[bind]]
 257        keys = "SPC m i"
 258        command = "org.item.toggle"
 259        mode = "normal"
 260        [[bind]]
 261        keys = "SPC m l l"
 262        command = "org.link.insert"
 263        mode = "normal"
 264        [[bind]]
 265        keys = "SPC m l s"
 266        command = "org.link.store"
 267        mode = "normal"
 268        [[bind]]
 269        keys = "SPC m l i"
 270        command = "org.id.store-link"
 271        mode = "normal"
 272        [[bind]]
 273        keys = "SPC n l"
 274        command = "org.link.store"
 275        mode = "normal"
 276        [[bind]]
 277        keys = "SPC m t"
 278        command = "org.todo.cycle"
 279        mode = "normal"
 280        [[bind]]
 281        keys = "SPC m q"
 282        command = "org.tags.set"
 283        mode = "normal"
 284        [[bind]]
 285        keys = "SPC m x"
 286        command = "org.checkbox.toggle"
 287        mode = "normal"
 288        [[bind]]
 289        keys = "SPC m A"
 290        command = "app.archive"
 291        mode = "normal"
 292        [[bind]]
 293        keys = "SPC m e h h"
 294        command = "app.export.html"
 295        mode = "normal"
 296        [[bind]]
 297        keys = "SPC m e h o"
 298        command = "app.export.html-open"
 299        mode = "normal"
 300        [[bind]]
 301        keys = "SPC m e m m"
 302        command = "app.export.markdown"
 303        mode = "normal"
 304        [[bind]]
 305        keys = "SPC m e l p"
 306        command = "app.export.pdf"
 307        mode = "normal"
 308        [[bind]]
 309        keys = "SPC m d d"
 310        command = "org.deadline"
 311        mode = "normal"
 312        [[bind]]
 313        keys = "SPC m d s"
 314        command = "org.schedule"
 315        mode = "normal"
 316        [[bind]]
 317        keys = "SPC m d t"
 318        command = "org.timestamp.active"
 319        mode = "normal"
 320        [[bind]]
 321        keys = "SPC m d T"
 322        command = "org.timestamp.inactive"
 323        mode = "normal"
 324        [[bind]]
 325        keys = "SPC m r r"
 326        command = "app.refile"
 327        mode = "normal"
 328        [[bind]]
 329        keys = "SPC m s r"
 330        command = "app.refile"
 331        mode = "normal"
 332        [[bind]]
 333        keys = "SPC m s A"
 334        command = "app.archive"
 335        mode = "normal"
 336        [[bind]]
 337        keys = "SPC m s a"
 338        command = "org.archive.toggle-tag"
 339        mode = "normal"
 340        [[bind]]
 341        keys = "SPC m s h"
 342        command = "org.subtree.promote"
 343        mode = "normal"
 344        [[bind]]
 345        keys = "SPC m s l"
 346        command = "org.subtree.demote"
 347        mode = "normal"
 348        [[bind]]
 349        keys = "SPC m s j"
 350        command = "org.subtree.down"
 351        mode = "normal"
 352        [[bind]]
 353        keys = "SPC m s k"
 354        command = "org.subtree.up"
 355        mode = "normal"
 356        [[bind]]
 357        keys = "SPC m c i"
 358        command = "app.clock.in"
 359        mode = "normal"
 360        [[bind]]
 361        keys = "SPC m c o"
 362        command = "app.clock.out"
 363        mode = "normal"
 364        [[bind]]
 365        keys = "SPC m c c"
 366        command = "app.clock.cancel"
 367        mode = "normal"
 368        [[bind]]
 369        keys = "SPC m c g"
 370        command = "app.clock.goto"
 371        mode = "normal"
 372        [[bind]]
 373        keys = "SPC m c R"
 374        command = "app.clock.report"
 375        mode = "normal"
 376        [[bind]]
 377        keys = "SPC m c E"
 378        command = "org.effort.set"
 379        mode = "normal"
 380        [[bind]]
 381        keys = "SPC m p p"
 382        command = "org.priority.set"
 383        mode = "normal"
 384        [[bind]]
 385        keys = "SPC m o"
 386        command = "org.property.read-and-set"
 387        mode = "normal"
 388        [[bind]]
 389        keys = "SPC m p u"
 390        command = "org.priority.up"
 391        mode = "normal"
 392        [[bind]]
 393        keys = "SPC m p d"
 394        command = "org.priority.down"
 395        mode = "normal"
 396        [[bind]]
 397        keys = "SPC m b -"
 398        command = "org.table.insert-hline"
 399        mode = "normal"
 400        [[bind]]
 401        keys = "SPC m b a"
 402        command = "org.table.align"
 403        mode = "normal"
 404        [[bind]]
 405        keys = "SPC m b r"
 406        command = "org.table.recalc-all"
 407        mode = "normal"
 408        [[bind]]
 409        keys = "SPC m b d c"
 410        command = "org.table.delete-column"
 411        mode = "normal"
 412        [[bind]]
 413        keys = "SPC m b d r"
 414        command = "org.table.kill-row"
 415        mode = "normal"
 416        [[bind]]
 417        keys = "SPC m b i c"
 418        command = "org.table.insert-column"
 419        mode = "normal"
 420        [[bind]]
 421        keys = "SPC m b i r"
 422        command = "org.table.insert-row"
 423        mode = "normal"
 424        [[bind]]
 425        keys = "SPC m b i h"
 426        command = "org.table.insert-hline"
 427        mode = "normal"
 428
 429        # evil-org and Doom's org keys
 430        [[bind]]
 431        keys = "TAB"
 432        command = "org.cycle"
 433        mode = "normal"
 434        [[bind]]
 435        keys = "S-TAB"
 436        command = "org.cycle-global"
 437        mode = "normal"
 438        [[bind]]
 439        keys = "RET"
 440        command = "org.dwim"
 441        mode = "normal"
 442        [[bind]]
 443        keys = "z a"
 444        command = "org.cycle"
 445        mode = "normal"
 446        [[bind]]
 447        keys = "z c"
 448        command = "org.cycle"
 449        mode = "normal"
 450        [[bind]]
 451        keys = "z o"
 452        command = "org.cycle"
 453        mode = "normal"
 454        [[bind]]
 455        keys = "z A"
 456        command = "org.cycle-global"
 457        mode = "normal"
 458        [[bind]]
 459        keys = "g h"
 460        command = "org.heading.up"
 461        mode = "normal"
 462        [[bind]]
 463        keys = "g j"
 464        command = "org.heading.forward-same-level"
 465        mode = "normal"
 466        [[bind]]
 467        keys = "g k"
 468        command = "org.heading.backward-same-level"
 469        mode = "normal"
 470        [[bind]]
 471        keys = "] h"
 472        command = "org.heading.forward-same-level"
 473        mode = "normal"
 474        [[bind]]
 475        keys = "[ h"
 476        command = "org.heading.backward-same-level"
 477        mode = "normal"
 478        [[bind]]
 479        keys = "RET"
 480        command = "org.table.next-row"
 481        when = "table"
 482        mode = "insert"
 483        [[bind]]
 484        keys = "TAB"
 485        command = "org.cycle"
 486        mode = "visual"
 487        [[bind]]
 488        keys = "S-TAB"
 489        command = "org.cycle-global"
 490        mode = "visual"
 491
 492        # Doom's corfu: completion-at-point in insert state.
 493        [[bind]]
 494        keys = "C-SPC"
 495        command = "editor.complete"
 496        mode = "insert"
 497        [[bind]]
 498        keys = "C-@"
 499        command = "editor.complete"
 500        mode = "insert"
 501
 502        # Insert state: org-cycle and org-shifttab with Doom's +org-indent-maybe-h, which
 503        # demotes or promotes a heading and indents or outdents an item tree.
 504        [[bind]]
 505        keys = "S-TAB"
 506        command = "org.cycle-global"
 507        mode = "insert"
 508        [[bind]]
 509        keys = "TAB"
 510        command = "org.table.next-field"
 511        when = "table"
 512        mode = "insert"
 513        [[bind]]
 514        keys = "S-TAB"
 515        command = "org.table.previous-field"
 516        when = "table"
 517        mode = "insert"
 518        [[bind]]
 519        keys = "TAB"
 520        command = "org.item.indent-tree"
 521        when = "item"
 522        mode = "insert"
 523        [[bind]]
 524        keys = "S-TAB"
 525        command = "org.item.outdent-tree"
 526        when = "item"
 527        mode = "insert"
 528        [[bind]]
 529        keys = "TAB"
 530        command = "org.heading.demote"
 531        when = "heading"
 532        mode = "insert"
 533        [[bind]]
 534        keys = "S-TAB"
 535        command = "org.heading.promote"
 536        when = "heading"
 537        mode = "insert"
 538
 539        """
 540
 541
 542    static let common = """
 543        [[bind]]
 544        keys = "TAB"
 545        command = "org.cycle"
 546        when = "heading"
 547        [[bind]]
 548        keys = "TAB"
 549        command = "org.cycle"
 550        when = "fold-line"
 551
 552        [[bind]]
 553        keys = "S-TAB"
 554        command = "org.cycle-global"
 555        [[bind]]
 556        keys = "TAB"
 557        command = "org.table.next-field"
 558        when = "table"
 559        [[bind]]
 560        keys = "S-TAB"
 561        command = "org.table.previous-field"
 562        when = "table"
 563        [[bind]]
 564        keys = "RET"
 565        command = "org.table.next-row"
 566        when = "table"
 567
 568        """
 569
 570    static let emacsBindings = """
 571        # Movement and editing. With a mark set (C-SPC), movement extends the region.
 572        [[bind]]
 573        keys = "C-f"
 574        command = "edit.forward-char"
 575        [[bind]]
 576        keys = "C-b"
 577        command = "edit.backward-char"
 578        [[bind]]
 579        keys = "C-n"
 580        command = "edit.next-line"
 581        [[bind]]
 582        keys = "C-p"
 583        command = "edit.previous-line"
 584        [[bind]]
 585        keys = "C-a"
 586        command = "edit.beginning-of-line"
 587        [[bind]]
 588        keys = "C-e"
 589        command = "edit.end-of-line"
 590        [[bind]]
 591        keys = "M-f"
 592        command = "edit.forward-word"
 593        [[bind]]
 594        keys = "M-b"
 595        command = "edit.backward-word"
 596        [[bind]]
 597        keys = "M-<"
 598        command = "edit.beginning-of-buffer"
 599        [[bind]]
 600        keys = "M->"
 601        command = "edit.end-of-buffer"
 602        [[bind]]
 603        keys = "C-v"
 604        command = "edit.scroll-up"
 605        [[bind]]
 606        keys = "M-v"
 607        command = "edit.scroll-down"
 608        [[bind]]
 609        keys = "C-l"
 610        command = "edit.recenter"
 611        [[bind]]
 612        keys = "C-d"
 613        command = "edit.delete-char"
 614        [[bind]]
 615        keys = "M-d"
 616        command = "edit.kill-word"
 617        [[bind]]
 618        keys = "M-DEL"
 619        command = "edit.backward-kill-word"
 620        [[bind]]
 621        keys = "C-k"
 622        command = "edit.kill-line"
 623        [[bind]]
 624        keys = "C-y"
 625        command = "edit.yank"
 626        [[bind]]
 627        keys = "C-SPC"
 628        command = "edit.set-mark"
 629        [[bind]]
 630        keys = "C-M-i"
 631        command = "editor.complete"
 632        [[bind]]
 633        keys = "C-x h"
 634        command = "edit.select-all"
 635        [[bind]]
 636        keys = "C-w"
 637        command = "edit.kill-region"
 638        [[bind]]
 639        keys = "M-w"
 640        command = "edit.copy-region"
 641        [[bind]]
 642        keys = "C-/"
 643        command = "edit.undo"
 644        [[bind]]
 645        keys = "C-_"
 646        command = "edit.undo"
 647        [[bind]]
 648        keys = "C-x u"
 649        command = "edit.undo"
 650        [[bind]]
 651        keys = "C-g"
 652        command = "edit.keyboard-quit"
 653        [[bind]]
 654        keys = "C-t"
 655        command = "edit.transpose-chars"
 656        [[bind]]
 657        keys = "C-s"
 658        command = "edit.find"
 659        [[bind]]
 660        keys = "C-r"
 661        command = "edit.find"
 662        [[bind]]
 663        keys = "M-%"
 664        command = "edit.replace"
 665
 666        # Files and commands
 667        [[bind]]
 668        keys = "C-x C-s"
 669        command = "app.save"
 670        [[bind]]
 671        keys = "C-c C-o"
 672        command = "org.link.open"
 673        [[bind]]
 674        keys = "C-c C-l"
 675        command = "org.link.insert"
 676        [[bind]]
 677        keys = "C-c l"
 678        command = "org.link.store"
 679        [[bind]]
 680        keys = "C-c ;"
 681        command = "org.heading.toggle-comment"
 682        [[bind]]
 683        keys = "C-c *"
 684        command = "org.heading.toggle"
 685        [[bind]]
 686        keys = "C-c -"
 687        command = "org.item.toggle"
 688        [[bind]]
 689        keys = "C-c @"
 690        command = "org.subtree.mark"
 691        [[bind]]
 692        keys = "C-c C-x C-w"
 693        command = "org.subtree.cut"
 694        [[bind]]
 695        keys = "C-c C-x M-w"
 696        command = "org.subtree.copy"
 697        [[bind]]
 698        keys = "C-c C-x C-y"
 699        command = "org.subtree.paste"
 700        [[bind]]
 701        keys = "C-c C-x c"
 702        command = "org.subtree.clone"
 703        [[bind]]
 704        keys = "C-c ^"
 705        command = "org.sort"
 706        [[bind]]
 707        keys = "C-c C-c"
 708        command = "org.ctrl-c-ctrl-c"
 709        [[bind]]
 710        keys = "C-c C-y"
 711        command = "org.timestamp.evaluate-range"
 712        [[bind]]
 713        keys = "C-c C-x f"
 714        command = "org.footnote.action"
 715        [[bind]]
 716        keys = "C-c ="
 717        command = "org.table.column-formula"
 718        [[bind]]
 719        keys = "C-c TAB"
 720        command = "org.table.toggle-column-width"
 721        when = "table"
 722        [[bind]]
 723        keys = "C-x n s"
 724        command = "org.narrow.subtree"
 725        [[bind]]
 726        keys = "C-x n b"
 727        command = "org.narrow.block"
 728        [[bind]]
 729        keys = "C-x n w"
 730        command = "org.widen"
 731        [[bind]]
 732        keys = "C-x x t"
 733        command = "editor.toggle-truncate-lines"
 734        [[bind]]
 735        keys = "C-c C-j"
 736        command = "org.goto"
 737        [[bind]]
 738        keys = "C-c /"
 739        command = "org.sparse-tree"
 740        [[bind]]
 741        keys = "C-c ,"
 742        command = "org.priority.set"
 743        [[bind]]
 744        keys = "C-c C-x p"
 745        command = "org.property.read-and-set"
 746        [[bind]]
 747        keys = "C-c C-x i"
 748        command = "org.columns.insert-dblock"
 749        [[bind]]
 750        keys = "C-c C-x a"
 751        command = "org.archive.toggle-tag"
 752        [[bind]]
 753        keys = "C-c C-x A"
 754        command = "org.archive.to-sibling"
 755        [[bind]]
 756        keys = "C-c C-e"
 757        command = "app.export-dialog"
 758        [[bind]]
 759        keys = "C-c C-x C-v"
 760        command = "org.toggle-inline-images"
 761        [[bind]]
 762        keys = "C-c C-x C-c"
 763        command = "org.columns"
 764        [[bind]]
 765        keys = "S-<right>"
 766        command = "org.property.next-value"
 767        when = "property"
 768        [[bind]]
 769        keys = "S-<left>"
 770        command = "org.property.previous-value"
 771        when = "property"
 772        [[bind]]
 773        keys = "C-c C-x C-r"
 774        command = "org.clock.report"
 775        [[bind]]
 776        keys = "C-c C-x C-u"
 777        command = "org.dblock.update"
 778        [[bind]]
 779        keys = "C-c C-x e"
 780        command = "org.effort.set"
 781        [[bind]]
 782        keys = "C-c C-c"
 783        command = "org.dblock.update"
 784        when = "dblock"
 785        [[bind]]
 786        keys = "C-c C-,"
 787        command = "org.structure-template"
 788        [[bind]]
 789        keys = "C-c '"
 790        command = "org.edit-special"
 791        [[bind]]
 792        keys = "C-c C-v t"
 793        command = "org.babel.tangle"
 794        [[bind]]
 795        keys = "C-c C-v C-t"
 796        command = "org.babel.tangle"
 797        [[bind]]
 798        keys = "C-c `"
 799        command = "org.table.edit-field"
 800        when = "table"
 801        [[bind]]
 802        keys = "C-x b"
 803        command = "app.buffer.switch"
 804        [[bind]]
 805        keys = "C-x C-b"
 806        command = "app.buffer.switch"
 807        [[bind]]
 808        keys = "C-x k"
 809        command = "app.buffer.kill"
 810        [[bind]]
 811        keys = "C-x <right>"
 812        command = "app.buffer.next"
 813        [[bind]]
 814        keys = "C-x <left>"
 815        command = "app.buffer.previous"
 816        [[bind]]
 817        keys = "C-x s"
 818        command = "app.save-all"
 819        [[bind]]
 820        keys = "C-x C-f"
 821        command = "app.quick-open"
 822        [[bind]]
 823        keys = "M-x"
 824        command = "app.palette"
 825        [[bind]]
 826        keys = "C-c a"
 827        command = "app.agenda"
 828        [[bind]]
 829        keys = "C-c c"
 830        command = "app.capture"
 831        [[bind]]
 832        keys = "C-c C-x C-i"
 833        command = "app.clock.in"
 834        [[bind]]
 835        keys = "C-c C-x C-o"
 836        command = "app.clock.out"
 837        [[bind]]
 838        keys = "C-c C-x C-q"
 839        command = "app.clock.cancel"
 840        [[bind]]
 841        keys = "C-c C-x C-j"
 842        command = "app.clock.goto"
 843        [[bind]]
 844        keys = "C-c C-e h h"
 845        command = "app.export.html"
 846        [[bind]]
 847        keys = "C-c C-e h o"
 848        command = "app.export.html-open"
 849        [[bind]]
 850        keys = "C-c C-e m m"
 851        command = "app.export.markdown"
 852        [[bind]]
 853        keys = "C-c C-e l p"
 854        command = "app.export.pdf"
 855        [[bind]]
 856        keys = "C-c C-e l l"
 857        command = "app.export.latex"
 858        [[bind]]
 859        keys = "C-c C-e o o"
 860        command = "app.export.odt"
 861        [[bind]]
 862        keys = "C-c C-e t u"
 863        command = "app.export.text"
 864
 865        # Org
 866        [[bind]]
 867        keys = "C-c C-t"
 868        command = "org.todo.cycle"
 869        [[bind]]
 870        keys = "S-<right>"
 871        command = "org.todo.next"
 872        when = "heading"
 873        [[bind]]
 874        keys = "S-<left>"
 875        command = "org.todo.previous"
 876        when = "heading"
 877        [[bind]]
 878        keys = "S-<up>"
 879        command = "org.priority.up"
 880        when = "heading"
 881        [[bind]]
 882        keys = "S-<down>"
 883        command = "org.priority.down"
 884        when = "heading"
 885        [[bind]]
 886        keys = "M-<left>"
 887        command = "org.heading.promote"
 888        when = "heading"
 889        [[bind]]
 890        keys = "M-<right>"
 891        command = "org.heading.demote"
 892        when = "heading"
 893        [[bind]]
 894        keys = "M-S-<left>"
 895        command = "org.subtree.promote"
 896        when = "heading"
 897        [[bind]]
 898        keys = "M-S-<right>"
 899        command = "org.subtree.demote"
 900        when = "heading"
 901        [[bind]]
 902        keys = "M-<up>"
 903        command = "org.subtree.up"
 904        when = "heading"
 905        [[bind]]
 906        keys = "M-<down>"
 907        command = "org.subtree.down"
 908        when = "heading"
 909        [[bind]]
 910        keys = "M-RET"
 911        command = "org.heading.insert"
 912        [[bind]]
 913        keys = "C-RET"
 914        command = "org.heading.insert-after-subtree"
 915        [[bind]]
 916        keys = "M-S-RET"
 917        command = "org.heading.insert-todo"
 918        [[bind]]
 919        keys = "C-c C-n"
 920        command = "org.heading.next"
 921        [[bind]]
 922        keys = "C-c C-p"
 923        command = "org.heading.previous"
 924        [[bind]]
 925        keys = "C-c C-f"
 926        command = "org.heading.forward-same-level"
 927        [[bind]]
 928        keys = "C-c C-b"
 929        command = "org.heading.backward-same-level"
 930        [[bind]]
 931        keys = "C-c C-u"
 932        command = "org.heading.up"
 933        [[bind]]
 934        keys = "C-c C-q"
 935        command = "org.tags.set"
 936        [[bind]]
 937        keys = "M-RET"
 938        command = "org.item.insert"
 939        when = "item"
 940        [[bind]]
 941        keys = "M-S-RET"
 942        command = "org.item.insert-checkbox"
 943        when = "item"
 944        [[bind]]
 945        keys = "M-<left>"
 946        command = "org.item.outdent"
 947        when = "item"
 948        [[bind]]
 949        keys = "M-<right>"
 950        command = "org.item.indent"
 951        when = "item"
 952        [[bind]]
 953        keys = "M-S-<left>"
 954        command = "org.item.outdent-tree"
 955        when = "item"
 956        [[bind]]
 957        keys = "M-S-<right>"
 958        command = "org.item.indent-tree"
 959        when = "item"
 960        [[bind]]
 961        keys = "M-<up>"
 962        command = "org.item.up"
 963        when = "item"
 964        [[bind]]
 965        keys = "M-<down>"
 966        command = "org.item.down"
 967        when = "item"
 968        [[bind]]
 969        keys = "C-c C-c"
 970        command = "org.ctrl-c-ctrl-c"
 971        when = "item"
 972        [[bind]]
 973        keys = "C-c C-x C-b"
 974        command = "org.checkbox.toggle"
 975        [[bind]]
 976        keys = "C-c C-w"
 977        command = "app.refile"
 978        [[bind]]
 979        keys = "C-c C-x C-s"
 980        command = "app.archive"
 981        [[bind]]
 982        keys = "C-c $"
 983        command = "app.archive"
 984        [[bind]]
 985        keys = "C-c ."
 986        command = "org.timestamp.active"
 987        [[bind]]
 988        keys = "C-c !"
 989        command = "org.timestamp.inactive"
 990        [[bind]]
 991        keys = "C-c C-s"
 992        command = "org.schedule"
 993        [[bind]]
 994        keys = "C-c C-d"
 995        command = "org.deadline"
 996        [[bind]]
 997        keys = "M-q"
 998        command = "org.fill-paragraph"
 999        [[bind]]
1000        keys = "C-c C-c"
1001        command = "org.table.align"
1002        when = "table"
1003        [[bind]]
1004        keys = "C-c C-c"
1005        command = "org.table.recalc-all"
1006        when = "tblfm"
1007        [[bind]]
1008        keys = "C-c *"
1009        command = "org.table.recalc"
1010        when = "table"
1011        [[bind]]
1012        keys = "C-c C-c"
1013        command = "org.babel.execute"
1014        when = "src"
1015        [[bind]]
1016        keys = "M-<up>"
1017        command = "org.table.row-up"
1018        when = "table"
1019        [[bind]]
1020        keys = "M-<down>"
1021        command = "org.table.row-down"
1022        when = "table"
1023        [[bind]]
1024        keys = "M-<left>"
1025        command = "org.table.column-left"
1026        when = "table"
1027        [[bind]]
1028        keys = "M-<right>"
1029        command = "org.table.column-right"
1030        when = "table"
1031        [[bind]]
1032        keys = "M-S-<right>"
1033        command = "org.table.insert-column"
1034        when = "table"
1035        [[bind]]
1036        keys = "M-S-<left>"
1037        command = "org.table.delete-column"
1038        when = "table"
1039        [[bind]]
1040        keys = "M-S-<up>"
1041        command = "org.table.kill-row"
1042        when = "table"
1043        [[bind]]
1044        keys = "M-S-<down>"
1045        command = "org.table.insert-row"
1046        when = "table"
1047        [[bind]]
1048        keys = "C-c -"
1049        command = "org.table.insert-hline"
1050        when = "table"
1051        [[bind]]
1052        keys = "C-c |"
1053        command = "org.table.create"
1054        [[bind]]
1055        keys = "S-<up>"
1056        command = "org.timestamp.up"
1057        when = "timestamp"
1058        [[bind]]
1059        keys = "S-<down>"
1060        command = "org.timestamp.down"
1061        when = "timestamp"
1062        [[bind]]
1063        keys = "S-<right>"
1064        command = "org.timestamp.day-later"
1065        when = "timestamp"
1066        [[bind]]
1067        keys = "S-<left>"
1068        command = "org.timestamp.day-earlier"
1069        when = "timestamp"
1070
1071        """
1072
1073    /// Standard Mac text keys stay as they are; org commands use Control-Command chords, which
1074    /// macOS text editing leaves free.
1075    static let macBindings = """
1076        [[bind]]
1077        keys = "C-TAB"
1078        command = "app.buffer.next"
1079        [[bind]]
1080        keys = "C-S-TAB"
1081        command = "app.buffer.previous"
1082        [[bind]]
1083        keys = "C-s-t"
1084        command = "org.todo.cycle"
1085        [[bind]]
1086        keys = "C-s-<up>"
1087        command = "org.priority.up"
1088        [[bind]]
1089        keys = "C-s-<down>"
1090        command = "org.priority.down"
1091        [[bind]]
1092        keys = "C-s-<left>"
1093        command = "org.heading.promote"
1094        [[bind]]
1095        keys = "C-s-<right>"
1096        command = "org.heading.demote"
1097        [[bind]]
1098        keys = "C-M-s-<left>"
1099        command = "org.subtree.promote"
1100        [[bind]]
1101        keys = "C-M-s-<right>"
1102        command = "org.subtree.demote"
1103        [[bind]]
1104        keys = "C-M-s-<up>"
1105        command = "org.subtree.up"
1106        [[bind]]
1107        keys = "C-M-s-<down>"
1108        command = "org.subtree.down"
1109        [[bind]]
1110        keys = "s-RET"
1111        command = "org.heading.insert"
1112        [[bind]]
1113        keys = "C-s-RET"
1114        command = "org.heading.insert-after-subtree"
1115        [[bind]]
1116        keys = "s-S-RET"
1117        command = "org.heading.insert-todo"
1118        [[bind]]
1119        keys = "M-s-<down>"
1120        command = "org.heading.next"
1121        [[bind]]
1122        keys = "M-s-<up>"
1123        command = "org.heading.previous"
1124        [[bind]]
1125        keys = "C-s-q"
1126        command = "org.tags.set"
1127        [[bind]]
1128        keys = "s-RET"
1129        command = "org.item.insert"
1130        when = "item"
1131        [[bind]]
1132        keys = "s-S-RET"
1133        command = "org.item.insert-checkbox"
1134        when = "item"
1135        [[bind]]
1136        keys = "C-s-<left>"
1137        command = "org.item.outdent"
1138        when = "item"
1139        [[bind]]
1140        keys = "C-s-<right>"
1141        command = "org.item.indent"
1142        when = "item"
1143        [[bind]]
1144        keys = "C-M-s-<left>"
1145        command = "org.item.outdent-tree"
1146        when = "item"
1147        [[bind]]
1148        keys = "C-M-s-<right>"
1149        command = "org.item.indent-tree"
1150        when = "item"
1151        [[bind]]
1152        keys = "C-M-s-<up>"
1153        command = "org.item.up"
1154        when = "item"
1155        [[bind]]
1156        keys = "C-M-s-<down>"
1157        command = "org.item.down"
1158        when = "item"
1159        [[bind]]
1160        keys = "C-s-c"
1161        command = "org.checkbox.toggle"
1162        [[bind]]
1163        keys = "C-s-w"
1164        command = "app.refile"
1165        [[bind]]
1166        keys = "C-s-a"
1167        command = "app.archive"
1168        [[bind]]
1169        keys = "C-s-."
1170        command = "org.timestamp.active"
1171        [[bind]]
1172        keys = "C-M-s-."
1173        command = "org.timestamp.inactive"
1174        [[bind]]
1175        keys = "C-s-s"
1176        command = "org.schedule"
1177        [[bind]]
1178        keys = "C-s-d"
1179        command = "org.deadline"
1180        [[bind]]
1181        keys = "C-s-p"
1182        command = "org.fill-paragraph"
1183        [[bind]]
1184        keys = "C-s-<up>"
1185        command = "org.table.row-up"
1186        when = "table"
1187        [[bind]]
1188        keys = "C-s-<down>"
1189        command = "org.table.row-down"
1190        when = "table"
1191        [[bind]]
1192        keys = "C-s-<left>"
1193        command = "org.table.column-left"
1194        when = "table"
1195        [[bind]]
1196        keys = "C-s-<right>"
1197        command = "org.table.column-right"
1198        when = "table"
1199        [[bind]]
1200        keys = "C-M-s-<right>"
1201        command = "org.table.insert-column"
1202        when = "table"
1203        [[bind]]
1204        keys = "C-M-s-<left>"
1205        command = "org.table.delete-column"
1206        when = "table"
1207        [[bind]]
1208        keys = "C-M-s-<up>"
1209        command = "org.table.kill-row"
1210        when = "table"
1211        [[bind]]
1212        keys = "C-M-s-<down>"
1213        command = "org.table.insert-row"
1214        when = "table"
1215        [[bind]]
1216        keys = "C-s--"
1217        command = "org.table.insert-hline"
1218        when = "table"
1219        [[bind]]
1220        keys = "C-s-\\\\"
1221        command = "org.table.create"
1222        [[bind]]
1223        keys = "C-s-<up>"
1224        command = "org.timestamp.up"
1225        when = "timestamp"
1226        [[bind]]
1227        keys = "C-s-<down>"
1228        command = "org.timestamp.down"
1229        when = "timestamp"
1230        [[bind]]
1231        keys = "C-s-<right>"
1232        command = "org.timestamp.day-later"
1233        when = "timestamp"
1234        [[bind]]
1235        keys = "C-s-<left>"
1236        command = "org.timestamp.day-earlier"
1237        when = "timestamp"
1238
1239        """
1240}