Sources/OrgCore/Keymap/Presets.swift

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

522 lines · 13646 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
  4
  5    public var title: String {
  6        switch self {
  7        case .emacs: "Emacs"
  8        case .mac: "Mac"
  9        }
 10    }
 11
 12    public var keymap: Keymap {
 13        var problems: [String] = []
 14        let map = try! Keymap(toml: toml, problems: &problems)
 15        precondition(problems.isEmpty, "preset \(rawValue): \(problems)")
 16        return map
 17    }
 18
 19    public var toml: String {
 20        switch self {
 21        case .emacs: Self.common + Self.emacsBindings
 22        case .mac: Self.common + Self.macBindings
 23        }
 24    }
 25
 26    static let common = """
 27        [[bind]]
 28        keys = "TAB"
 29        command = "org.cycle"
 30        when = "heading"
 31
 32        [[bind]]
 33        keys = "S-TAB"
 34        command = "org.cycle-global"
 35        [[bind]]
 36        keys = "TAB"
 37        command = "org.table.next-field"
 38        when = "table"
 39        [[bind]]
 40        keys = "S-TAB"
 41        command = "org.table.previous-field"
 42        when = "table"
 43        [[bind]]
 44        keys = "RET"
 45        command = "org.table.next-row"
 46        when = "table"
 47
 48        """
 49
 50    static let emacsBindings = """
 51        # Movement and editing. With a mark set (C-SPC), movement extends the region.
 52        [[bind]]
 53        keys = "C-f"
 54        command = "edit.forward-char"
 55        [[bind]]
 56        keys = "C-b"
 57        command = "edit.backward-char"
 58        [[bind]]
 59        keys = "C-n"
 60        command = "edit.next-line"
 61        [[bind]]
 62        keys = "C-p"
 63        command = "edit.previous-line"
 64        [[bind]]
 65        keys = "C-a"
 66        command = "edit.beginning-of-line"
 67        [[bind]]
 68        keys = "C-e"
 69        command = "edit.end-of-line"
 70        [[bind]]
 71        keys = "M-f"
 72        command = "edit.forward-word"
 73        [[bind]]
 74        keys = "M-b"
 75        command = "edit.backward-word"
 76        [[bind]]
 77        keys = "M-<"
 78        command = "edit.beginning-of-buffer"
 79        [[bind]]
 80        keys = "M->"
 81        command = "edit.end-of-buffer"
 82        [[bind]]
 83        keys = "C-v"
 84        command = "edit.scroll-up"
 85        [[bind]]
 86        keys = "M-v"
 87        command = "edit.scroll-down"
 88        [[bind]]
 89        keys = "C-l"
 90        command = "edit.recenter"
 91        [[bind]]
 92        keys = "C-d"
 93        command = "edit.delete-char"
 94        [[bind]]
 95        keys = "M-d"
 96        command = "edit.kill-word"
 97        [[bind]]
 98        keys = "M-DEL"
 99        command = "edit.backward-kill-word"
100        [[bind]]
101        keys = "C-k"
102        command = "edit.kill-line"
103        [[bind]]
104        keys = "C-y"
105        command = "edit.yank"
106        [[bind]]
107        keys = "C-SPC"
108        command = "edit.set-mark"
109        [[bind]]
110        keys = "C-x h"
111        command = "edit.select-all"
112        [[bind]]
113        keys = "C-w"
114        command = "edit.kill-region"
115        [[bind]]
116        keys = "M-w"
117        command = "edit.copy-region"
118        [[bind]]
119        keys = "C-/"
120        command = "edit.undo"
121        [[bind]]
122        keys = "C-_"
123        command = "edit.undo"
124        [[bind]]
125        keys = "C-x u"
126        command = "edit.undo"
127        [[bind]]
128        keys = "C-g"
129        command = "edit.keyboard-quit"
130        [[bind]]
131        keys = "C-t"
132        command = "edit.transpose-chars"
133        [[bind]]
134        keys = "C-s"
135        command = "edit.find"
136        [[bind]]
137        keys = "C-r"
138        command = "edit.find"
139
140        # Files and commands
141        [[bind]]
142        keys = "C-x C-s"
143        command = "app.save"
144        [[bind]]
145        keys = "C-x C-f"
146        command = "app.quick-open"
147        [[bind]]
148        keys = "C-x b"
149        command = "app.quick-open"
150        [[bind]]
151        keys = "M-x"
152        command = "app.palette"
153        [[bind]]
154        keys = "C-c a"
155        command = "app.agenda"
156
157        # Org
158        [[bind]]
159        keys = "C-c C-t"
160        command = "org.todo.cycle"
161        [[bind]]
162        keys = "S-<right>"
163        command = "org.todo.cycle"
164        when = "heading"
165        [[bind]]
166        keys = "S-<up>"
167        command = "org.priority.up"
168        when = "heading"
169        [[bind]]
170        keys = "S-<down>"
171        command = "org.priority.down"
172        when = "heading"
173        [[bind]]
174        keys = "M-<left>"
175        command = "org.heading.promote"
176        when = "heading"
177        [[bind]]
178        keys = "M-<right>"
179        command = "org.heading.demote"
180        when = "heading"
181        [[bind]]
182        keys = "M-S-<left>"
183        command = "org.subtree.promote"
184        when = "heading"
185        [[bind]]
186        keys = "M-S-<right>"
187        command = "org.subtree.demote"
188        when = "heading"
189        [[bind]]
190        keys = "M-<up>"
191        command = "org.subtree.up"
192        when = "heading"
193        [[bind]]
194        keys = "M-<down>"
195        command = "org.subtree.down"
196        when = "heading"
197        [[bind]]
198        keys = "M-RET"
199        command = "org.heading.insert"
200        [[bind]]
201        keys = "C-RET"
202        command = "org.heading.insert-after-subtree"
203        [[bind]]
204        keys = "M-S-RET"
205        command = "org.heading.insert-todo"
206        [[bind]]
207        keys = "C-c C-n"
208        command = "org.heading.next"
209        [[bind]]
210        keys = "C-c C-p"
211        command = "org.heading.previous"
212        [[bind]]
213        keys = "C-c C-f"
214        command = "org.heading.forward-same-level"
215        [[bind]]
216        keys = "C-c C-b"
217        command = "org.heading.backward-same-level"
218        [[bind]]
219        keys = "C-c C-u"
220        command = "org.heading.up"
221        [[bind]]
222        keys = "C-c C-q"
223        command = "org.tags.set"
224        [[bind]]
225        keys = "M-RET"
226        command = "org.item.insert"
227        when = "item"
228        [[bind]]
229        keys = "M-S-RET"
230        command = "org.item.insert-checkbox"
231        when = "item"
232        [[bind]]
233        keys = "M-<left>"
234        command = "org.item.outdent"
235        when = "item"
236        [[bind]]
237        keys = "M-<right>"
238        command = "org.item.indent"
239        when = "item"
240        [[bind]]
241        keys = "M-S-<left>"
242        command = "org.item.outdent-tree"
243        when = "item"
244        [[bind]]
245        keys = "M-S-<right>"
246        command = "org.item.indent-tree"
247        when = "item"
248        [[bind]]
249        keys = "M-<up>"
250        command = "org.item.up"
251        when = "item"
252        [[bind]]
253        keys = "M-<down>"
254        command = "org.item.down"
255        when = "item"
256        [[bind]]
257        keys = "C-c C-c"
258        command = "org.checkbox.toggle"
259        when = "item"
260        [[bind]]
261        keys = "C-c C-x C-b"
262        command = "org.checkbox.toggle"
263        [[bind]]
264        keys = "C-c C-w"
265        command = "app.refile"
266        [[bind]]
267        keys = "C-c C-x C-s"
268        command = "app.archive"
269        [[bind]]
270        keys = "C-c $"
271        command = "app.archive"
272        [[bind]]
273        keys = "C-c ."
274        command = "org.timestamp.active"
275        [[bind]]
276        keys = "C-c !"
277        command = "org.timestamp.inactive"
278        [[bind]]
279        keys = "C-c C-s"
280        command = "org.schedule"
281        [[bind]]
282        keys = "C-c C-d"
283        command = "org.deadline"
284        [[bind]]
285        keys = "M-q"
286        command = "org.fill-paragraph"
287        [[bind]]
288        keys = "C-c C-c"
289        command = "org.table.align"
290        when = "table"
291        [[bind]]
292        keys = "C-c C-c"
293        command = "org.table.recalc-all"
294        when = "tblfm"
295        [[bind]]
296        keys = "C-c *"
297        command = "org.table.recalc"
298        when = "table"
299        [[bind]]
300        keys = "C-c C-c"
301        command = "org.babel.execute"
302        when = "src"
303        [[bind]]
304        keys = "M-<up>"
305        command = "org.table.row-up"
306        when = "table"
307        [[bind]]
308        keys = "M-<down>"
309        command = "org.table.row-down"
310        when = "table"
311        [[bind]]
312        keys = "M-<left>"
313        command = "org.table.column-left"
314        when = "table"
315        [[bind]]
316        keys = "M-<right>"
317        command = "org.table.column-right"
318        when = "table"
319        [[bind]]
320        keys = "M-S-<right>"
321        command = "org.table.insert-column"
322        when = "table"
323        [[bind]]
324        keys = "M-S-<left>"
325        command = "org.table.delete-column"
326        when = "table"
327        [[bind]]
328        keys = "M-S-<up>"
329        command = "org.table.kill-row"
330        when = "table"
331        [[bind]]
332        keys = "M-S-<down>"
333        command = "org.table.insert-row"
334        when = "table"
335        [[bind]]
336        keys = "C-c -"
337        command = "org.table.insert-hline"
338        when = "table"
339        [[bind]]
340        keys = "C-c |"
341        command = "org.table.create"
342        [[bind]]
343        keys = "S-<up>"
344        command = "org.timestamp.up"
345        when = "timestamp"
346        [[bind]]
347        keys = "S-<down>"
348        command = "org.timestamp.down"
349        when = "timestamp"
350        [[bind]]
351        keys = "S-<right>"
352        command = "org.timestamp.day-later"
353        when = "timestamp"
354        [[bind]]
355        keys = "S-<left>"
356        command = "org.timestamp.day-earlier"
357        when = "timestamp"
358
359        """
360
361    /// Standard Mac text keys stay as they are; org commands use Control-Command chords, which
362    /// macOS text editing leaves free.
363    static let macBindings = """
364        [[bind]]
365        keys = "C-s-t"
366        command = "org.todo.cycle"
367        [[bind]]
368        keys = "C-s-<up>"
369        command = "org.priority.up"
370        [[bind]]
371        keys = "C-s-<down>"
372        command = "org.priority.down"
373        [[bind]]
374        keys = "C-s-<left>"
375        command = "org.heading.promote"
376        [[bind]]
377        keys = "C-s-<right>"
378        command = "org.heading.demote"
379        [[bind]]
380        keys = "C-M-s-<left>"
381        command = "org.subtree.promote"
382        [[bind]]
383        keys = "C-M-s-<right>"
384        command = "org.subtree.demote"
385        [[bind]]
386        keys = "C-M-s-<up>"
387        command = "org.subtree.up"
388        [[bind]]
389        keys = "C-M-s-<down>"
390        command = "org.subtree.down"
391        [[bind]]
392        keys = "s-RET"
393        command = "org.heading.insert"
394        [[bind]]
395        keys = "C-s-RET"
396        command = "org.heading.insert-after-subtree"
397        [[bind]]
398        keys = "s-S-RET"
399        command = "org.heading.insert-todo"
400        [[bind]]
401        keys = "M-s-<down>"
402        command = "org.heading.next"
403        [[bind]]
404        keys = "M-s-<up>"
405        command = "org.heading.previous"
406        [[bind]]
407        keys = "C-s-q"
408        command = "org.tags.set"
409        [[bind]]
410        keys = "s-RET"
411        command = "org.item.insert"
412        when = "item"
413        [[bind]]
414        keys = "s-S-RET"
415        command = "org.item.insert-checkbox"
416        when = "item"
417        [[bind]]
418        keys = "C-s-<left>"
419        command = "org.item.outdent"
420        when = "item"
421        [[bind]]
422        keys = "C-s-<right>"
423        command = "org.item.indent"
424        when = "item"
425        [[bind]]
426        keys = "C-M-s-<left>"
427        command = "org.item.outdent-tree"
428        when = "item"
429        [[bind]]
430        keys = "C-M-s-<right>"
431        command = "org.item.indent-tree"
432        when = "item"
433        [[bind]]
434        keys = "C-M-s-<up>"
435        command = "org.item.up"
436        when = "item"
437        [[bind]]
438        keys = "C-M-s-<down>"
439        command = "org.item.down"
440        when = "item"
441        [[bind]]
442        keys = "C-s-c"
443        command = "org.checkbox.toggle"
444        [[bind]]
445        keys = "C-s-w"
446        command = "app.refile"
447        [[bind]]
448        keys = "C-s-a"
449        command = "app.archive"
450        [[bind]]
451        keys = "C-s-."
452        command = "org.timestamp.active"
453        [[bind]]
454        keys = "C-M-s-."
455        command = "org.timestamp.inactive"
456        [[bind]]
457        keys = "C-s-s"
458        command = "org.schedule"
459        [[bind]]
460        keys = "C-s-d"
461        command = "org.deadline"
462        [[bind]]
463        keys = "C-s-p"
464        command = "org.fill-paragraph"
465        [[bind]]
466        keys = "C-s-<up>"
467        command = "org.table.row-up"
468        when = "table"
469        [[bind]]
470        keys = "C-s-<down>"
471        command = "org.table.row-down"
472        when = "table"
473        [[bind]]
474        keys = "C-s-<left>"
475        command = "org.table.column-left"
476        when = "table"
477        [[bind]]
478        keys = "C-s-<right>"
479        command = "org.table.column-right"
480        when = "table"
481        [[bind]]
482        keys = "C-M-s-<right>"
483        command = "org.table.insert-column"
484        when = "table"
485        [[bind]]
486        keys = "C-M-s-<left>"
487        command = "org.table.delete-column"
488        when = "table"
489        [[bind]]
490        keys = "C-M-s-<up>"
491        command = "org.table.kill-row"
492        when = "table"
493        [[bind]]
494        keys = "C-M-s-<down>"
495        command = "org.table.insert-row"
496        when = "table"
497        [[bind]]
498        keys = "C-s--"
499        command = "org.table.insert-hline"
500        when = "table"
501        [[bind]]
502        keys = "C-s-\\\\"
503        command = "org.table.create"
504        [[bind]]
505        keys = "C-s-<up>"
506        command = "org.timestamp.up"
507        when = "timestamp"
508        [[bind]]
509        keys = "C-s-<down>"
510        command = "org.timestamp.down"
511        when = "timestamp"
512        [[bind]]
513        keys = "C-s-<right>"
514        command = "org.timestamp.day-later"
515        when = "timestamp"
516        [[bind]]
517        keys = "C-s-<left>"
518        command = "org.timestamp.day-earlier"
519        when = "timestamp"
520
521        """
522}