Sources/OrgCore/Keymap/Presets.swift

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

1234 lines · 34949 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 `"
 793        command = "org.table.edit-field"
 794        when = "table"
 795        [[bind]]
 796        keys = "C-x b"
 797        command = "app.buffer.switch"
 798        [[bind]]
 799        keys = "C-x C-b"
 800        command = "app.buffer.switch"
 801        [[bind]]
 802        keys = "C-x k"
 803        command = "app.buffer.kill"
 804        [[bind]]
 805        keys = "C-x <right>"
 806        command = "app.buffer.next"
 807        [[bind]]
 808        keys = "C-x <left>"
 809        command = "app.buffer.previous"
 810        [[bind]]
 811        keys = "C-x s"
 812        command = "app.save-all"
 813        [[bind]]
 814        keys = "C-x C-f"
 815        command = "app.quick-open"
 816        [[bind]]
 817        keys = "M-x"
 818        command = "app.palette"
 819        [[bind]]
 820        keys = "C-c a"
 821        command = "app.agenda"
 822        [[bind]]
 823        keys = "C-c c"
 824        command = "app.capture"
 825        [[bind]]
 826        keys = "C-c C-x C-i"
 827        command = "app.clock.in"
 828        [[bind]]
 829        keys = "C-c C-x C-o"
 830        command = "app.clock.out"
 831        [[bind]]
 832        keys = "C-c C-x C-q"
 833        command = "app.clock.cancel"
 834        [[bind]]
 835        keys = "C-c C-x C-j"
 836        command = "app.clock.goto"
 837        [[bind]]
 838        keys = "C-c C-e h h"
 839        command = "app.export.html"
 840        [[bind]]
 841        keys = "C-c C-e h o"
 842        command = "app.export.html-open"
 843        [[bind]]
 844        keys = "C-c C-e m m"
 845        command = "app.export.markdown"
 846        [[bind]]
 847        keys = "C-c C-e l p"
 848        command = "app.export.pdf"
 849        [[bind]]
 850        keys = "C-c C-e l l"
 851        command = "app.export.latex"
 852        [[bind]]
 853        keys = "C-c C-e o o"
 854        command = "app.export.odt"
 855        [[bind]]
 856        keys = "C-c C-e t u"
 857        command = "app.export.text"
 858
 859        # Org
 860        [[bind]]
 861        keys = "C-c C-t"
 862        command = "org.todo.cycle"
 863        [[bind]]
 864        keys = "S-<right>"
 865        command = "org.todo.next"
 866        when = "heading"
 867        [[bind]]
 868        keys = "S-<left>"
 869        command = "org.todo.previous"
 870        when = "heading"
 871        [[bind]]
 872        keys = "S-<up>"
 873        command = "org.priority.up"
 874        when = "heading"
 875        [[bind]]
 876        keys = "S-<down>"
 877        command = "org.priority.down"
 878        when = "heading"
 879        [[bind]]
 880        keys = "M-<left>"
 881        command = "org.heading.promote"
 882        when = "heading"
 883        [[bind]]
 884        keys = "M-<right>"
 885        command = "org.heading.demote"
 886        when = "heading"
 887        [[bind]]
 888        keys = "M-S-<left>"
 889        command = "org.subtree.promote"
 890        when = "heading"
 891        [[bind]]
 892        keys = "M-S-<right>"
 893        command = "org.subtree.demote"
 894        when = "heading"
 895        [[bind]]
 896        keys = "M-<up>"
 897        command = "org.subtree.up"
 898        when = "heading"
 899        [[bind]]
 900        keys = "M-<down>"
 901        command = "org.subtree.down"
 902        when = "heading"
 903        [[bind]]
 904        keys = "M-RET"
 905        command = "org.heading.insert"
 906        [[bind]]
 907        keys = "C-RET"
 908        command = "org.heading.insert-after-subtree"
 909        [[bind]]
 910        keys = "M-S-RET"
 911        command = "org.heading.insert-todo"
 912        [[bind]]
 913        keys = "C-c C-n"
 914        command = "org.heading.next"
 915        [[bind]]
 916        keys = "C-c C-p"
 917        command = "org.heading.previous"
 918        [[bind]]
 919        keys = "C-c C-f"
 920        command = "org.heading.forward-same-level"
 921        [[bind]]
 922        keys = "C-c C-b"
 923        command = "org.heading.backward-same-level"
 924        [[bind]]
 925        keys = "C-c C-u"
 926        command = "org.heading.up"
 927        [[bind]]
 928        keys = "C-c C-q"
 929        command = "org.tags.set"
 930        [[bind]]
 931        keys = "M-RET"
 932        command = "org.item.insert"
 933        when = "item"
 934        [[bind]]
 935        keys = "M-S-RET"
 936        command = "org.item.insert-checkbox"
 937        when = "item"
 938        [[bind]]
 939        keys = "M-<left>"
 940        command = "org.item.outdent"
 941        when = "item"
 942        [[bind]]
 943        keys = "M-<right>"
 944        command = "org.item.indent"
 945        when = "item"
 946        [[bind]]
 947        keys = "M-S-<left>"
 948        command = "org.item.outdent-tree"
 949        when = "item"
 950        [[bind]]
 951        keys = "M-S-<right>"
 952        command = "org.item.indent-tree"
 953        when = "item"
 954        [[bind]]
 955        keys = "M-<up>"
 956        command = "org.item.up"
 957        when = "item"
 958        [[bind]]
 959        keys = "M-<down>"
 960        command = "org.item.down"
 961        when = "item"
 962        [[bind]]
 963        keys = "C-c C-c"
 964        command = "org.ctrl-c-ctrl-c"
 965        when = "item"
 966        [[bind]]
 967        keys = "C-c C-x C-b"
 968        command = "org.checkbox.toggle"
 969        [[bind]]
 970        keys = "C-c C-w"
 971        command = "app.refile"
 972        [[bind]]
 973        keys = "C-c C-x C-s"
 974        command = "app.archive"
 975        [[bind]]
 976        keys = "C-c $"
 977        command = "app.archive"
 978        [[bind]]
 979        keys = "C-c ."
 980        command = "org.timestamp.active"
 981        [[bind]]
 982        keys = "C-c !"
 983        command = "org.timestamp.inactive"
 984        [[bind]]
 985        keys = "C-c C-s"
 986        command = "org.schedule"
 987        [[bind]]
 988        keys = "C-c C-d"
 989        command = "org.deadline"
 990        [[bind]]
 991        keys = "M-q"
 992        command = "org.fill-paragraph"
 993        [[bind]]
 994        keys = "C-c C-c"
 995        command = "org.table.align"
 996        when = "table"
 997        [[bind]]
 998        keys = "C-c C-c"
 999        command = "org.table.recalc-all"
1000        when = "tblfm"
1001        [[bind]]
1002        keys = "C-c *"
1003        command = "org.table.recalc"
1004        when = "table"
1005        [[bind]]
1006        keys = "C-c C-c"
1007        command = "org.babel.execute"
1008        when = "src"
1009        [[bind]]
1010        keys = "M-<up>"
1011        command = "org.table.row-up"
1012        when = "table"
1013        [[bind]]
1014        keys = "M-<down>"
1015        command = "org.table.row-down"
1016        when = "table"
1017        [[bind]]
1018        keys = "M-<left>"
1019        command = "org.table.column-left"
1020        when = "table"
1021        [[bind]]
1022        keys = "M-<right>"
1023        command = "org.table.column-right"
1024        when = "table"
1025        [[bind]]
1026        keys = "M-S-<right>"
1027        command = "org.table.insert-column"
1028        when = "table"
1029        [[bind]]
1030        keys = "M-S-<left>"
1031        command = "org.table.delete-column"
1032        when = "table"
1033        [[bind]]
1034        keys = "M-S-<up>"
1035        command = "org.table.kill-row"
1036        when = "table"
1037        [[bind]]
1038        keys = "M-S-<down>"
1039        command = "org.table.insert-row"
1040        when = "table"
1041        [[bind]]
1042        keys = "C-c -"
1043        command = "org.table.insert-hline"
1044        when = "table"
1045        [[bind]]
1046        keys = "C-c |"
1047        command = "org.table.create"
1048        [[bind]]
1049        keys = "S-<up>"
1050        command = "org.timestamp.up"
1051        when = "timestamp"
1052        [[bind]]
1053        keys = "S-<down>"
1054        command = "org.timestamp.down"
1055        when = "timestamp"
1056        [[bind]]
1057        keys = "S-<right>"
1058        command = "org.timestamp.day-later"
1059        when = "timestamp"
1060        [[bind]]
1061        keys = "S-<left>"
1062        command = "org.timestamp.day-earlier"
1063        when = "timestamp"
1064
1065        """
1066
1067    /// Standard Mac text keys stay as they are; org commands use Control-Command chords, which
1068    /// macOS text editing leaves free.
1069    static let macBindings = """
1070        [[bind]]
1071        keys = "C-TAB"
1072        command = "app.buffer.next"
1073        [[bind]]
1074        keys = "C-S-TAB"
1075        command = "app.buffer.previous"
1076        [[bind]]
1077        keys = "C-s-t"
1078        command = "org.todo.cycle"
1079        [[bind]]
1080        keys = "C-s-<up>"
1081        command = "org.priority.up"
1082        [[bind]]
1083        keys = "C-s-<down>"
1084        command = "org.priority.down"
1085        [[bind]]
1086        keys = "C-s-<left>"
1087        command = "org.heading.promote"
1088        [[bind]]
1089        keys = "C-s-<right>"
1090        command = "org.heading.demote"
1091        [[bind]]
1092        keys = "C-M-s-<left>"
1093        command = "org.subtree.promote"
1094        [[bind]]
1095        keys = "C-M-s-<right>"
1096        command = "org.subtree.demote"
1097        [[bind]]
1098        keys = "C-M-s-<up>"
1099        command = "org.subtree.up"
1100        [[bind]]
1101        keys = "C-M-s-<down>"
1102        command = "org.subtree.down"
1103        [[bind]]
1104        keys = "s-RET"
1105        command = "org.heading.insert"
1106        [[bind]]
1107        keys = "C-s-RET"
1108        command = "org.heading.insert-after-subtree"
1109        [[bind]]
1110        keys = "s-S-RET"
1111        command = "org.heading.insert-todo"
1112        [[bind]]
1113        keys = "M-s-<down>"
1114        command = "org.heading.next"
1115        [[bind]]
1116        keys = "M-s-<up>"
1117        command = "org.heading.previous"
1118        [[bind]]
1119        keys = "C-s-q"
1120        command = "org.tags.set"
1121        [[bind]]
1122        keys = "s-RET"
1123        command = "org.item.insert"
1124        when = "item"
1125        [[bind]]
1126        keys = "s-S-RET"
1127        command = "org.item.insert-checkbox"
1128        when = "item"
1129        [[bind]]
1130        keys = "C-s-<left>"
1131        command = "org.item.outdent"
1132        when = "item"
1133        [[bind]]
1134        keys = "C-s-<right>"
1135        command = "org.item.indent"
1136        when = "item"
1137        [[bind]]
1138        keys = "C-M-s-<left>"
1139        command = "org.item.outdent-tree"
1140        when = "item"
1141        [[bind]]
1142        keys = "C-M-s-<right>"
1143        command = "org.item.indent-tree"
1144        when = "item"
1145        [[bind]]
1146        keys = "C-M-s-<up>"
1147        command = "org.item.up"
1148        when = "item"
1149        [[bind]]
1150        keys = "C-M-s-<down>"
1151        command = "org.item.down"
1152        when = "item"
1153        [[bind]]
1154        keys = "C-s-c"
1155        command = "org.checkbox.toggle"
1156        [[bind]]
1157        keys = "C-s-w"
1158        command = "app.refile"
1159        [[bind]]
1160        keys = "C-s-a"
1161        command = "app.archive"
1162        [[bind]]
1163        keys = "C-s-."
1164        command = "org.timestamp.active"
1165        [[bind]]
1166        keys = "C-M-s-."
1167        command = "org.timestamp.inactive"
1168        [[bind]]
1169        keys = "C-s-s"
1170        command = "org.schedule"
1171        [[bind]]
1172        keys = "C-s-d"
1173        command = "org.deadline"
1174        [[bind]]
1175        keys = "C-s-p"
1176        command = "org.fill-paragraph"
1177        [[bind]]
1178        keys = "C-s-<up>"
1179        command = "org.table.row-up"
1180        when = "table"
1181        [[bind]]
1182        keys = "C-s-<down>"
1183        command = "org.table.row-down"
1184        when = "table"
1185        [[bind]]
1186        keys = "C-s-<left>"
1187        command = "org.table.column-left"
1188        when = "table"
1189        [[bind]]
1190        keys = "C-s-<right>"
1191        command = "org.table.column-right"
1192        when = "table"
1193        [[bind]]
1194        keys = "C-M-s-<right>"
1195        command = "org.table.insert-column"
1196        when = "table"
1197        [[bind]]
1198        keys = "C-M-s-<left>"
1199        command = "org.table.delete-column"
1200        when = "table"
1201        [[bind]]
1202        keys = "C-M-s-<up>"
1203        command = "org.table.kill-row"
1204        when = "table"
1205        [[bind]]
1206        keys = "C-M-s-<down>"
1207        command = "org.table.insert-row"
1208        when = "table"
1209        [[bind]]
1210        keys = "C-s--"
1211        command = "org.table.insert-hline"
1212        when = "table"
1213        [[bind]]
1214        keys = "C-s-\\\\"
1215        command = "org.table.create"
1216        [[bind]]
1217        keys = "C-s-<up>"
1218        command = "org.timestamp.up"
1219        when = "timestamp"
1220        [[bind]]
1221        keys = "C-s-<down>"
1222        command = "org.timestamp.down"
1223        when = "timestamp"
1224        [[bind]]
1225        keys = "C-s-<right>"
1226        command = "org.timestamp.day-later"
1227        when = "timestamp"
1228        [[bind]]
1229        keys = "C-s-<left>"
1230        command = "org.timestamp.day-earlier"
1231        when = "timestamp"
1232
1233        """
1234}