Sources/OrgCore/Keymap/Presets.swift

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

558 lines · 14623 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        [[bind]]
157        keys = "C-c c"
158        command = "app.capture"
159        [[bind]]
160        keys = "C-c C-x C-i"
161        command = "app.clock.in"
162        [[bind]]
163        keys = "C-c C-x C-o"
164        command = "app.clock.out"
165        [[bind]]
166        keys = "C-c C-x C-q"
167        command = "app.clock.cancel"
168        [[bind]]
169        keys = "C-c C-x C-j"
170        command = "app.clock.goto"
171        [[bind]]
172        keys = "C-c C-e h h"
173        command = "app.export.html"
174        [[bind]]
175        keys = "C-c C-e h o"
176        command = "app.export.html-open"
177        [[bind]]
178        keys = "C-c C-e m m"
179        command = "app.export.markdown"
180        [[bind]]
181        keys = "C-c C-e l p"
182        command = "app.export.pdf"
183        [[bind]]
184        keys = "C-c C-e l l"
185        command = "app.export.latex"
186        [[bind]]
187        keys = "C-c C-e o o"
188        command = "app.export.odt"
189        [[bind]]
190        keys = "C-c C-e t u"
191        command = "app.export.text"
192
193        # Org
194        [[bind]]
195        keys = "C-c C-t"
196        command = "org.todo.cycle"
197        [[bind]]
198        keys = "S-<right>"
199        command = "org.todo.cycle"
200        when = "heading"
201        [[bind]]
202        keys = "S-<up>"
203        command = "org.priority.up"
204        when = "heading"
205        [[bind]]
206        keys = "S-<down>"
207        command = "org.priority.down"
208        when = "heading"
209        [[bind]]
210        keys = "M-<left>"
211        command = "org.heading.promote"
212        when = "heading"
213        [[bind]]
214        keys = "M-<right>"
215        command = "org.heading.demote"
216        when = "heading"
217        [[bind]]
218        keys = "M-S-<left>"
219        command = "org.subtree.promote"
220        when = "heading"
221        [[bind]]
222        keys = "M-S-<right>"
223        command = "org.subtree.demote"
224        when = "heading"
225        [[bind]]
226        keys = "M-<up>"
227        command = "org.subtree.up"
228        when = "heading"
229        [[bind]]
230        keys = "M-<down>"
231        command = "org.subtree.down"
232        when = "heading"
233        [[bind]]
234        keys = "M-RET"
235        command = "org.heading.insert"
236        [[bind]]
237        keys = "C-RET"
238        command = "org.heading.insert-after-subtree"
239        [[bind]]
240        keys = "M-S-RET"
241        command = "org.heading.insert-todo"
242        [[bind]]
243        keys = "C-c C-n"
244        command = "org.heading.next"
245        [[bind]]
246        keys = "C-c C-p"
247        command = "org.heading.previous"
248        [[bind]]
249        keys = "C-c C-f"
250        command = "org.heading.forward-same-level"
251        [[bind]]
252        keys = "C-c C-b"
253        command = "org.heading.backward-same-level"
254        [[bind]]
255        keys = "C-c C-u"
256        command = "org.heading.up"
257        [[bind]]
258        keys = "C-c C-q"
259        command = "org.tags.set"
260        [[bind]]
261        keys = "M-RET"
262        command = "org.item.insert"
263        when = "item"
264        [[bind]]
265        keys = "M-S-RET"
266        command = "org.item.insert-checkbox"
267        when = "item"
268        [[bind]]
269        keys = "M-<left>"
270        command = "org.item.outdent"
271        when = "item"
272        [[bind]]
273        keys = "M-<right>"
274        command = "org.item.indent"
275        when = "item"
276        [[bind]]
277        keys = "M-S-<left>"
278        command = "org.item.outdent-tree"
279        when = "item"
280        [[bind]]
281        keys = "M-S-<right>"
282        command = "org.item.indent-tree"
283        when = "item"
284        [[bind]]
285        keys = "M-<up>"
286        command = "org.item.up"
287        when = "item"
288        [[bind]]
289        keys = "M-<down>"
290        command = "org.item.down"
291        when = "item"
292        [[bind]]
293        keys = "C-c C-c"
294        command = "org.checkbox.toggle"
295        when = "item"
296        [[bind]]
297        keys = "C-c C-x C-b"
298        command = "org.checkbox.toggle"
299        [[bind]]
300        keys = "C-c C-w"
301        command = "app.refile"
302        [[bind]]
303        keys = "C-c C-x C-s"
304        command = "app.archive"
305        [[bind]]
306        keys = "C-c $"
307        command = "app.archive"
308        [[bind]]
309        keys = "C-c ."
310        command = "org.timestamp.active"
311        [[bind]]
312        keys = "C-c !"
313        command = "org.timestamp.inactive"
314        [[bind]]
315        keys = "C-c C-s"
316        command = "org.schedule"
317        [[bind]]
318        keys = "C-c C-d"
319        command = "org.deadline"
320        [[bind]]
321        keys = "M-q"
322        command = "org.fill-paragraph"
323        [[bind]]
324        keys = "C-c C-c"
325        command = "org.table.align"
326        when = "table"
327        [[bind]]
328        keys = "C-c C-c"
329        command = "org.table.recalc-all"
330        when = "tblfm"
331        [[bind]]
332        keys = "C-c *"
333        command = "org.table.recalc"
334        when = "table"
335        [[bind]]
336        keys = "C-c C-c"
337        command = "org.babel.execute"
338        when = "src"
339        [[bind]]
340        keys = "M-<up>"
341        command = "org.table.row-up"
342        when = "table"
343        [[bind]]
344        keys = "M-<down>"
345        command = "org.table.row-down"
346        when = "table"
347        [[bind]]
348        keys = "M-<left>"
349        command = "org.table.column-left"
350        when = "table"
351        [[bind]]
352        keys = "M-<right>"
353        command = "org.table.column-right"
354        when = "table"
355        [[bind]]
356        keys = "M-S-<right>"
357        command = "org.table.insert-column"
358        when = "table"
359        [[bind]]
360        keys = "M-S-<left>"
361        command = "org.table.delete-column"
362        when = "table"
363        [[bind]]
364        keys = "M-S-<up>"
365        command = "org.table.kill-row"
366        when = "table"
367        [[bind]]
368        keys = "M-S-<down>"
369        command = "org.table.insert-row"
370        when = "table"
371        [[bind]]
372        keys = "C-c -"
373        command = "org.table.insert-hline"
374        when = "table"
375        [[bind]]
376        keys = "C-c |"
377        command = "org.table.create"
378        [[bind]]
379        keys = "S-<up>"
380        command = "org.timestamp.up"
381        when = "timestamp"
382        [[bind]]
383        keys = "S-<down>"
384        command = "org.timestamp.down"
385        when = "timestamp"
386        [[bind]]
387        keys = "S-<right>"
388        command = "org.timestamp.day-later"
389        when = "timestamp"
390        [[bind]]
391        keys = "S-<left>"
392        command = "org.timestamp.day-earlier"
393        when = "timestamp"
394
395        """
396
397    /// Standard Mac text keys stay as they are; org commands use Control-Command chords, which
398    /// macOS text editing leaves free.
399    static let macBindings = """
400        [[bind]]
401        keys = "C-s-t"
402        command = "org.todo.cycle"
403        [[bind]]
404        keys = "C-s-<up>"
405        command = "org.priority.up"
406        [[bind]]
407        keys = "C-s-<down>"
408        command = "org.priority.down"
409        [[bind]]
410        keys = "C-s-<left>"
411        command = "org.heading.promote"
412        [[bind]]
413        keys = "C-s-<right>"
414        command = "org.heading.demote"
415        [[bind]]
416        keys = "C-M-s-<left>"
417        command = "org.subtree.promote"
418        [[bind]]
419        keys = "C-M-s-<right>"
420        command = "org.subtree.demote"
421        [[bind]]
422        keys = "C-M-s-<up>"
423        command = "org.subtree.up"
424        [[bind]]
425        keys = "C-M-s-<down>"
426        command = "org.subtree.down"
427        [[bind]]
428        keys = "s-RET"
429        command = "org.heading.insert"
430        [[bind]]
431        keys = "C-s-RET"
432        command = "org.heading.insert-after-subtree"
433        [[bind]]
434        keys = "s-S-RET"
435        command = "org.heading.insert-todo"
436        [[bind]]
437        keys = "M-s-<down>"
438        command = "org.heading.next"
439        [[bind]]
440        keys = "M-s-<up>"
441        command = "org.heading.previous"
442        [[bind]]
443        keys = "C-s-q"
444        command = "org.tags.set"
445        [[bind]]
446        keys = "s-RET"
447        command = "org.item.insert"
448        when = "item"
449        [[bind]]
450        keys = "s-S-RET"
451        command = "org.item.insert-checkbox"
452        when = "item"
453        [[bind]]
454        keys = "C-s-<left>"
455        command = "org.item.outdent"
456        when = "item"
457        [[bind]]
458        keys = "C-s-<right>"
459        command = "org.item.indent"
460        when = "item"
461        [[bind]]
462        keys = "C-M-s-<left>"
463        command = "org.item.outdent-tree"
464        when = "item"
465        [[bind]]
466        keys = "C-M-s-<right>"
467        command = "org.item.indent-tree"
468        when = "item"
469        [[bind]]
470        keys = "C-M-s-<up>"
471        command = "org.item.up"
472        when = "item"
473        [[bind]]
474        keys = "C-M-s-<down>"
475        command = "org.item.down"
476        when = "item"
477        [[bind]]
478        keys = "C-s-c"
479        command = "org.checkbox.toggle"
480        [[bind]]
481        keys = "C-s-w"
482        command = "app.refile"
483        [[bind]]
484        keys = "C-s-a"
485        command = "app.archive"
486        [[bind]]
487        keys = "C-s-."
488        command = "org.timestamp.active"
489        [[bind]]
490        keys = "C-M-s-."
491        command = "org.timestamp.inactive"
492        [[bind]]
493        keys = "C-s-s"
494        command = "org.schedule"
495        [[bind]]
496        keys = "C-s-d"
497        command = "org.deadline"
498        [[bind]]
499        keys = "C-s-p"
500        command = "org.fill-paragraph"
501        [[bind]]
502        keys = "C-s-<up>"
503        command = "org.table.row-up"
504        when = "table"
505        [[bind]]
506        keys = "C-s-<down>"
507        command = "org.table.row-down"
508        when = "table"
509        [[bind]]
510        keys = "C-s-<left>"
511        command = "org.table.column-left"
512        when = "table"
513        [[bind]]
514        keys = "C-s-<right>"
515        command = "org.table.column-right"
516        when = "table"
517        [[bind]]
518        keys = "C-M-s-<right>"
519        command = "org.table.insert-column"
520        when = "table"
521        [[bind]]
522        keys = "C-M-s-<left>"
523        command = "org.table.delete-column"
524        when = "table"
525        [[bind]]
526        keys = "C-M-s-<up>"
527        command = "org.table.kill-row"
528        when = "table"
529        [[bind]]
530        keys = "C-M-s-<down>"
531        command = "org.table.insert-row"
532        when = "table"
533        [[bind]]
534        keys = "C-s--"
535        command = "org.table.insert-hline"
536        when = "table"
537        [[bind]]
538        keys = "C-s-\\\\"
539        command = "org.table.create"
540        [[bind]]
541        keys = "C-s-<up>"
542        command = "org.timestamp.up"
543        when = "timestamp"
544        [[bind]]
545        keys = "C-s-<down>"
546        command = "org.timestamp.down"
547        when = "timestamp"
548        [[bind]]
549        keys = "C-s-<right>"
550        command = "org.timestamp.day-later"
551        when = "timestamp"
552        [[bind]]
553        keys = "C-s-<left>"
554        command = "org.timestamp.day-earlier"
555        when = "timestamp"
556
557        """
558}