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