Sources/OrgCore/Keymap/Presets.swift

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

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