Sources/OrgCore/Keymap/Presets.swift

25a6d84c1f41024c27ce1de5be1d3bf6425f76d0
orgstar/Sources/OrgCore/Keymap/Presets.swift history · blame · raw

1217 lines · 34509 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        # Insert state: org-cycle and org-shifttab with Doom's +org-indent-maybe-h, which
 493        # demotes or promotes a heading and indents or outdents an item tree.
 494        [[bind]]
 495        keys = "S-TAB"
 496        command = "org.cycle-global"
 497        mode = "insert"
 498        [[bind]]
 499        keys = "TAB"
 500        command = "org.table.next-field"
 501        when = "table"
 502        mode = "insert"
 503        [[bind]]
 504        keys = "S-TAB"
 505        command = "org.table.previous-field"
 506        when = "table"
 507        mode = "insert"
 508        [[bind]]
 509        keys = "TAB"
 510        command = "org.item.indent-tree"
 511        when = "item"
 512        mode = "insert"
 513        [[bind]]
 514        keys = "S-TAB"
 515        command = "org.item.outdent-tree"
 516        when = "item"
 517        mode = "insert"
 518        [[bind]]
 519        keys = "TAB"
 520        command = "org.heading.demote"
 521        when = "heading"
 522        mode = "insert"
 523        [[bind]]
 524        keys = "S-TAB"
 525        command = "org.heading.promote"
 526        when = "heading"
 527        mode = "insert"
 528
 529        """
 530
 531
 532    static let common = """
 533        [[bind]]
 534        keys = "TAB"
 535        command = "org.cycle"
 536        when = "heading"
 537        [[bind]]
 538        keys = "TAB"
 539        command = "org.cycle"
 540        when = "fold-line"
 541
 542        [[bind]]
 543        keys = "S-TAB"
 544        command = "org.cycle-global"
 545        [[bind]]
 546        keys = "TAB"
 547        command = "org.table.next-field"
 548        when = "table"
 549        [[bind]]
 550        keys = "S-TAB"
 551        command = "org.table.previous-field"
 552        when = "table"
 553        [[bind]]
 554        keys = "RET"
 555        command = "org.table.next-row"
 556        when = "table"
 557
 558        """
 559
 560    static let emacsBindings = """
 561        # Movement and editing. With a mark set (C-SPC), movement extends the region.
 562        [[bind]]
 563        keys = "C-f"
 564        command = "edit.forward-char"
 565        [[bind]]
 566        keys = "C-b"
 567        command = "edit.backward-char"
 568        [[bind]]
 569        keys = "C-n"
 570        command = "edit.next-line"
 571        [[bind]]
 572        keys = "C-p"
 573        command = "edit.previous-line"
 574        [[bind]]
 575        keys = "C-a"
 576        command = "edit.beginning-of-line"
 577        [[bind]]
 578        keys = "C-e"
 579        command = "edit.end-of-line"
 580        [[bind]]
 581        keys = "M-f"
 582        command = "edit.forward-word"
 583        [[bind]]
 584        keys = "M-b"
 585        command = "edit.backward-word"
 586        [[bind]]
 587        keys = "M-<"
 588        command = "edit.beginning-of-buffer"
 589        [[bind]]
 590        keys = "M->"
 591        command = "edit.end-of-buffer"
 592        [[bind]]
 593        keys = "C-v"
 594        command = "edit.scroll-up"
 595        [[bind]]
 596        keys = "M-v"
 597        command = "edit.scroll-down"
 598        [[bind]]
 599        keys = "C-l"
 600        command = "edit.recenter"
 601        [[bind]]
 602        keys = "C-d"
 603        command = "edit.delete-char"
 604        [[bind]]
 605        keys = "M-d"
 606        command = "edit.kill-word"
 607        [[bind]]
 608        keys = "M-DEL"
 609        command = "edit.backward-kill-word"
 610        [[bind]]
 611        keys = "C-k"
 612        command = "edit.kill-line"
 613        [[bind]]
 614        keys = "C-y"
 615        command = "edit.yank"
 616        [[bind]]
 617        keys = "C-SPC"
 618        command = "edit.set-mark"
 619        [[bind]]
 620        keys = "C-x h"
 621        command = "edit.select-all"
 622        [[bind]]
 623        keys = "C-w"
 624        command = "edit.kill-region"
 625        [[bind]]
 626        keys = "M-w"
 627        command = "edit.copy-region"
 628        [[bind]]
 629        keys = "C-/"
 630        command = "edit.undo"
 631        [[bind]]
 632        keys = "C-_"
 633        command = "edit.undo"
 634        [[bind]]
 635        keys = "C-x u"
 636        command = "edit.undo"
 637        [[bind]]
 638        keys = "C-g"
 639        command = "edit.keyboard-quit"
 640        [[bind]]
 641        keys = "C-t"
 642        command = "edit.transpose-chars"
 643        [[bind]]
 644        keys = "C-s"
 645        command = "edit.find"
 646        [[bind]]
 647        keys = "C-r"
 648        command = "edit.find"
 649        [[bind]]
 650        keys = "M-%"
 651        command = "edit.replace"
 652
 653        # Files and commands
 654        [[bind]]
 655        keys = "C-x C-s"
 656        command = "app.save"
 657        [[bind]]
 658        keys = "C-c C-o"
 659        command = "org.link.open"
 660        [[bind]]
 661        keys = "C-c C-l"
 662        command = "org.link.insert"
 663        [[bind]]
 664        keys = "C-c l"
 665        command = "org.link.store"
 666        [[bind]]
 667        keys = "C-c ;"
 668        command = "org.heading.toggle-comment"
 669        [[bind]]
 670        keys = "C-c *"
 671        command = "org.heading.toggle"
 672        [[bind]]
 673        keys = "C-c -"
 674        command = "org.item.toggle"
 675        [[bind]]
 676        keys = "C-c @"
 677        command = "org.subtree.mark"
 678        [[bind]]
 679        keys = "C-c C-x C-w"
 680        command = "org.subtree.cut"
 681        [[bind]]
 682        keys = "C-c C-x M-w"
 683        command = "org.subtree.copy"
 684        [[bind]]
 685        keys = "C-c C-x C-y"
 686        command = "org.subtree.paste"
 687        [[bind]]
 688        keys = "C-c C-x c"
 689        command = "org.subtree.clone"
 690        [[bind]]
 691        keys = "C-c ^"
 692        command = "org.sort"
 693        [[bind]]
 694        keys = "C-c C-c"
 695        command = "org.ctrl-c-ctrl-c"
 696        [[bind]]
 697        keys = "C-c C-y"
 698        command = "org.timestamp.evaluate-range"
 699        [[bind]]
 700        keys = "C-c C-x f"
 701        command = "org.footnote.action"
 702        [[bind]]
 703        keys = "C-c ="
 704        command = "org.table.column-formula"
 705        [[bind]]
 706        keys = "C-c TAB"
 707        command = "org.table.toggle-column-width"
 708        when = "table"
 709        [[bind]]
 710        keys = "C-x n s"
 711        command = "org.narrow.subtree"
 712        [[bind]]
 713        keys = "C-x n b"
 714        command = "org.narrow.block"
 715        [[bind]]
 716        keys = "C-x n w"
 717        command = "org.widen"
 718        [[bind]]
 719        keys = "C-x x t"
 720        command = "editor.toggle-truncate-lines"
 721        [[bind]]
 722        keys = "C-c C-j"
 723        command = "org.goto"
 724        [[bind]]
 725        keys = "C-c /"
 726        command = "org.sparse-tree"
 727        [[bind]]
 728        keys = "C-c ,"
 729        command = "org.priority.set"
 730        [[bind]]
 731        keys = "C-c C-x p"
 732        command = "org.property.read-and-set"
 733        [[bind]]
 734        keys = "C-c C-x i"
 735        command = "org.columns.insert-dblock"
 736        [[bind]]
 737        keys = "C-c C-x a"
 738        command = "org.archive.toggle-tag"
 739        [[bind]]
 740        keys = "C-c C-x A"
 741        command = "org.archive.to-sibling"
 742        [[bind]]
 743        keys = "C-c C-e"
 744        command = "app.export-dialog"
 745        [[bind]]
 746        keys = "C-c C-x C-v"
 747        command = "org.toggle-inline-images"
 748        [[bind]]
 749        keys = "C-c C-x C-c"
 750        command = "org.columns"
 751        [[bind]]
 752        keys = "S-<right>"
 753        command = "org.property.next-value"
 754        when = "property"
 755        [[bind]]
 756        keys = "S-<left>"
 757        command = "org.property.previous-value"
 758        when = "property"
 759        [[bind]]
 760        keys = "C-c C-x C-r"
 761        command = "org.clock.report"
 762        [[bind]]
 763        keys = "C-c C-x C-u"
 764        command = "org.dblock.update"
 765        [[bind]]
 766        keys = "C-c C-x e"
 767        command = "org.effort.set"
 768        [[bind]]
 769        keys = "C-c C-c"
 770        command = "org.dblock.update"
 771        when = "dblock"
 772        [[bind]]
 773        keys = "C-c C-,"
 774        command = "org.structure-template"
 775        [[bind]]
 776        keys = "C-c '"
 777        command = "org.edit-special"
 778        [[bind]]
 779        keys = "C-x b"
 780        command = "app.buffer.switch"
 781        [[bind]]
 782        keys = "C-x C-b"
 783        command = "app.buffer.switch"
 784        [[bind]]
 785        keys = "C-x k"
 786        command = "app.buffer.kill"
 787        [[bind]]
 788        keys = "C-x <right>"
 789        command = "app.buffer.next"
 790        [[bind]]
 791        keys = "C-x <left>"
 792        command = "app.buffer.previous"
 793        [[bind]]
 794        keys = "C-x s"
 795        command = "app.save-all"
 796        [[bind]]
 797        keys = "C-x C-f"
 798        command = "app.quick-open"
 799        [[bind]]
 800        keys = "M-x"
 801        command = "app.palette"
 802        [[bind]]
 803        keys = "C-c a"
 804        command = "app.agenda"
 805        [[bind]]
 806        keys = "C-c c"
 807        command = "app.capture"
 808        [[bind]]
 809        keys = "C-c C-x C-i"
 810        command = "app.clock.in"
 811        [[bind]]
 812        keys = "C-c C-x C-o"
 813        command = "app.clock.out"
 814        [[bind]]
 815        keys = "C-c C-x C-q"
 816        command = "app.clock.cancel"
 817        [[bind]]
 818        keys = "C-c C-x C-j"
 819        command = "app.clock.goto"
 820        [[bind]]
 821        keys = "C-c C-e h h"
 822        command = "app.export.html"
 823        [[bind]]
 824        keys = "C-c C-e h o"
 825        command = "app.export.html-open"
 826        [[bind]]
 827        keys = "C-c C-e m m"
 828        command = "app.export.markdown"
 829        [[bind]]
 830        keys = "C-c C-e l p"
 831        command = "app.export.pdf"
 832        [[bind]]
 833        keys = "C-c C-e l l"
 834        command = "app.export.latex"
 835        [[bind]]
 836        keys = "C-c C-e o o"
 837        command = "app.export.odt"
 838        [[bind]]
 839        keys = "C-c C-e t u"
 840        command = "app.export.text"
 841
 842        # Org
 843        [[bind]]
 844        keys = "C-c C-t"
 845        command = "org.todo.cycle"
 846        [[bind]]
 847        keys = "S-<right>"
 848        command = "org.todo.next"
 849        when = "heading"
 850        [[bind]]
 851        keys = "S-<left>"
 852        command = "org.todo.previous"
 853        when = "heading"
 854        [[bind]]
 855        keys = "S-<up>"
 856        command = "org.priority.up"
 857        when = "heading"
 858        [[bind]]
 859        keys = "S-<down>"
 860        command = "org.priority.down"
 861        when = "heading"
 862        [[bind]]
 863        keys = "M-<left>"
 864        command = "org.heading.promote"
 865        when = "heading"
 866        [[bind]]
 867        keys = "M-<right>"
 868        command = "org.heading.demote"
 869        when = "heading"
 870        [[bind]]
 871        keys = "M-S-<left>"
 872        command = "org.subtree.promote"
 873        when = "heading"
 874        [[bind]]
 875        keys = "M-S-<right>"
 876        command = "org.subtree.demote"
 877        when = "heading"
 878        [[bind]]
 879        keys = "M-<up>"
 880        command = "org.subtree.up"
 881        when = "heading"
 882        [[bind]]
 883        keys = "M-<down>"
 884        command = "org.subtree.down"
 885        when = "heading"
 886        [[bind]]
 887        keys = "M-RET"
 888        command = "org.heading.insert"
 889        [[bind]]
 890        keys = "C-RET"
 891        command = "org.heading.insert-after-subtree"
 892        [[bind]]
 893        keys = "M-S-RET"
 894        command = "org.heading.insert-todo"
 895        [[bind]]
 896        keys = "C-c C-n"
 897        command = "org.heading.next"
 898        [[bind]]
 899        keys = "C-c C-p"
 900        command = "org.heading.previous"
 901        [[bind]]
 902        keys = "C-c C-f"
 903        command = "org.heading.forward-same-level"
 904        [[bind]]
 905        keys = "C-c C-b"
 906        command = "org.heading.backward-same-level"
 907        [[bind]]
 908        keys = "C-c C-u"
 909        command = "org.heading.up"
 910        [[bind]]
 911        keys = "C-c C-q"
 912        command = "org.tags.set"
 913        [[bind]]
 914        keys = "M-RET"
 915        command = "org.item.insert"
 916        when = "item"
 917        [[bind]]
 918        keys = "M-S-RET"
 919        command = "org.item.insert-checkbox"
 920        when = "item"
 921        [[bind]]
 922        keys = "M-<left>"
 923        command = "org.item.outdent"
 924        when = "item"
 925        [[bind]]
 926        keys = "M-<right>"
 927        command = "org.item.indent"
 928        when = "item"
 929        [[bind]]
 930        keys = "M-S-<left>"
 931        command = "org.item.outdent-tree"
 932        when = "item"
 933        [[bind]]
 934        keys = "M-S-<right>"
 935        command = "org.item.indent-tree"
 936        when = "item"
 937        [[bind]]
 938        keys = "M-<up>"
 939        command = "org.item.up"
 940        when = "item"
 941        [[bind]]
 942        keys = "M-<down>"
 943        command = "org.item.down"
 944        when = "item"
 945        [[bind]]
 946        keys = "C-c C-c"
 947        command = "org.ctrl-c-ctrl-c"
 948        when = "item"
 949        [[bind]]
 950        keys = "C-c C-x C-b"
 951        command = "org.checkbox.toggle"
 952        [[bind]]
 953        keys = "C-c C-w"
 954        command = "app.refile"
 955        [[bind]]
 956        keys = "C-c C-x C-s"
 957        command = "app.archive"
 958        [[bind]]
 959        keys = "C-c $"
 960        command = "app.archive"
 961        [[bind]]
 962        keys = "C-c ."
 963        command = "org.timestamp.active"
 964        [[bind]]
 965        keys = "C-c !"
 966        command = "org.timestamp.inactive"
 967        [[bind]]
 968        keys = "C-c C-s"
 969        command = "org.schedule"
 970        [[bind]]
 971        keys = "C-c C-d"
 972        command = "org.deadline"
 973        [[bind]]
 974        keys = "M-q"
 975        command = "org.fill-paragraph"
 976        [[bind]]
 977        keys = "C-c C-c"
 978        command = "org.table.align"
 979        when = "table"
 980        [[bind]]
 981        keys = "C-c C-c"
 982        command = "org.table.recalc-all"
 983        when = "tblfm"
 984        [[bind]]
 985        keys = "C-c *"
 986        command = "org.table.recalc"
 987        when = "table"
 988        [[bind]]
 989        keys = "C-c C-c"
 990        command = "org.babel.execute"
 991        when = "src"
 992        [[bind]]
 993        keys = "M-<up>"
 994        command = "org.table.row-up"
 995        when = "table"
 996        [[bind]]
 997        keys = "M-<down>"
 998        command = "org.table.row-down"
 999        when = "table"
1000        [[bind]]
1001        keys = "M-<left>"
1002        command = "org.table.column-left"
1003        when = "table"
1004        [[bind]]
1005        keys = "M-<right>"
1006        command = "org.table.column-right"
1007        when = "table"
1008        [[bind]]
1009        keys = "M-S-<right>"
1010        command = "org.table.insert-column"
1011        when = "table"
1012        [[bind]]
1013        keys = "M-S-<left>"
1014        command = "org.table.delete-column"
1015        when = "table"
1016        [[bind]]
1017        keys = "M-S-<up>"
1018        command = "org.table.kill-row"
1019        when = "table"
1020        [[bind]]
1021        keys = "M-S-<down>"
1022        command = "org.table.insert-row"
1023        when = "table"
1024        [[bind]]
1025        keys = "C-c -"
1026        command = "org.table.insert-hline"
1027        when = "table"
1028        [[bind]]
1029        keys = "C-c |"
1030        command = "org.table.create"
1031        [[bind]]
1032        keys = "S-<up>"
1033        command = "org.timestamp.up"
1034        when = "timestamp"
1035        [[bind]]
1036        keys = "S-<down>"
1037        command = "org.timestamp.down"
1038        when = "timestamp"
1039        [[bind]]
1040        keys = "S-<right>"
1041        command = "org.timestamp.day-later"
1042        when = "timestamp"
1043        [[bind]]
1044        keys = "S-<left>"
1045        command = "org.timestamp.day-earlier"
1046        when = "timestamp"
1047
1048        """
1049
1050    /// Standard Mac text keys stay as they are; org commands use Control-Command chords, which
1051    /// macOS text editing leaves free.
1052    static let macBindings = """
1053        [[bind]]
1054        keys = "C-TAB"
1055        command = "app.buffer.next"
1056        [[bind]]
1057        keys = "C-S-TAB"
1058        command = "app.buffer.previous"
1059        [[bind]]
1060        keys = "C-s-t"
1061        command = "org.todo.cycle"
1062        [[bind]]
1063        keys = "C-s-<up>"
1064        command = "org.priority.up"
1065        [[bind]]
1066        keys = "C-s-<down>"
1067        command = "org.priority.down"
1068        [[bind]]
1069        keys = "C-s-<left>"
1070        command = "org.heading.promote"
1071        [[bind]]
1072        keys = "C-s-<right>"
1073        command = "org.heading.demote"
1074        [[bind]]
1075        keys = "C-M-s-<left>"
1076        command = "org.subtree.promote"
1077        [[bind]]
1078        keys = "C-M-s-<right>"
1079        command = "org.subtree.demote"
1080        [[bind]]
1081        keys = "C-M-s-<up>"
1082        command = "org.subtree.up"
1083        [[bind]]
1084        keys = "C-M-s-<down>"
1085        command = "org.subtree.down"
1086        [[bind]]
1087        keys = "s-RET"
1088        command = "org.heading.insert"
1089        [[bind]]
1090        keys = "C-s-RET"
1091        command = "org.heading.insert-after-subtree"
1092        [[bind]]
1093        keys = "s-S-RET"
1094        command = "org.heading.insert-todo"
1095        [[bind]]
1096        keys = "M-s-<down>"
1097        command = "org.heading.next"
1098        [[bind]]
1099        keys = "M-s-<up>"
1100        command = "org.heading.previous"
1101        [[bind]]
1102        keys = "C-s-q"
1103        command = "org.tags.set"
1104        [[bind]]
1105        keys = "s-RET"
1106        command = "org.item.insert"
1107        when = "item"
1108        [[bind]]
1109        keys = "s-S-RET"
1110        command = "org.item.insert-checkbox"
1111        when = "item"
1112        [[bind]]
1113        keys = "C-s-<left>"
1114        command = "org.item.outdent"
1115        when = "item"
1116        [[bind]]
1117        keys = "C-s-<right>"
1118        command = "org.item.indent"
1119        when = "item"
1120        [[bind]]
1121        keys = "C-M-s-<left>"
1122        command = "org.item.outdent-tree"
1123        when = "item"
1124        [[bind]]
1125        keys = "C-M-s-<right>"
1126        command = "org.item.indent-tree"
1127        when = "item"
1128        [[bind]]
1129        keys = "C-M-s-<up>"
1130        command = "org.item.up"
1131        when = "item"
1132        [[bind]]
1133        keys = "C-M-s-<down>"
1134        command = "org.item.down"
1135        when = "item"
1136        [[bind]]
1137        keys = "C-s-c"
1138        command = "org.checkbox.toggle"
1139        [[bind]]
1140        keys = "C-s-w"
1141        command = "app.refile"
1142        [[bind]]
1143        keys = "C-s-a"
1144        command = "app.archive"
1145        [[bind]]
1146        keys = "C-s-."
1147        command = "org.timestamp.active"
1148        [[bind]]
1149        keys = "C-M-s-."
1150        command = "org.timestamp.inactive"
1151        [[bind]]
1152        keys = "C-s-s"
1153        command = "org.schedule"
1154        [[bind]]
1155        keys = "C-s-d"
1156        command = "org.deadline"
1157        [[bind]]
1158        keys = "C-s-p"
1159        command = "org.fill-paragraph"
1160        [[bind]]
1161        keys = "C-s-<up>"
1162        command = "org.table.row-up"
1163        when = "table"
1164        [[bind]]
1165        keys = "C-s-<down>"
1166        command = "org.table.row-down"
1167        when = "table"
1168        [[bind]]
1169        keys = "C-s-<left>"
1170        command = "org.table.column-left"
1171        when = "table"
1172        [[bind]]
1173        keys = "C-s-<right>"
1174        command = "org.table.column-right"
1175        when = "table"
1176        [[bind]]
1177        keys = "C-M-s-<right>"
1178        command = "org.table.insert-column"
1179        when = "table"
1180        [[bind]]
1181        keys = "C-M-s-<left>"
1182        command = "org.table.delete-column"
1183        when = "table"
1184        [[bind]]
1185        keys = "C-M-s-<up>"
1186        command = "org.table.kill-row"
1187        when = "table"
1188        [[bind]]
1189        keys = "C-M-s-<down>"
1190        command = "org.table.insert-row"
1191        when = "table"
1192        [[bind]]
1193        keys = "C-s--"
1194        command = "org.table.insert-hline"
1195        when = "table"
1196        [[bind]]
1197        keys = "C-s-\\\\"
1198        command = "org.table.create"
1199        [[bind]]
1200        keys = "C-s-<up>"
1201        command = "org.timestamp.up"
1202        when = "timestamp"
1203        [[bind]]
1204        keys = "C-s-<down>"
1205        command = "org.timestamp.down"
1206        when = "timestamp"
1207        [[bind]]
1208        keys = "C-s-<right>"
1209        command = "org.timestamp.day-later"
1210        when = "timestamp"
1211        [[bind]]
1212        keys = "C-s-<left>"
1213        command = "org.timestamp.day-earlier"
1214        when = "timestamp"
1215
1216        """
1217}