Sources/OrgCore/Keymap/Presets.swift
510 lines · 13339 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 = "M-<up>"
293 command = "org.table.row-up"
294 when = "table"
295 [[bind]]
296 keys = "M-<down>"
297 command = "org.table.row-down"
298 when = "table"
299 [[bind]]
300 keys = "M-<left>"
301 command = "org.table.column-left"
302 when = "table"
303 [[bind]]
304 keys = "M-<right>"
305 command = "org.table.column-right"
306 when = "table"
307 [[bind]]
308 keys = "M-S-<right>"
309 command = "org.table.insert-column"
310 when = "table"
311 [[bind]]
312 keys = "M-S-<left>"
313 command = "org.table.delete-column"
314 when = "table"
315 [[bind]]
316 keys = "M-S-<up>"
317 command = "org.table.kill-row"
318 when = "table"
319 [[bind]]
320 keys = "M-S-<down>"
321 command = "org.table.insert-row"
322 when = "table"
323 [[bind]]
324 keys = "C-c -"
325 command = "org.table.insert-hline"
326 when = "table"
327 [[bind]]
328 keys = "C-c |"
329 command = "org.table.create"
330 [[bind]]
331 keys = "S-<up>"
332 command = "org.timestamp.up"
333 when = "timestamp"
334 [[bind]]
335 keys = "S-<down>"
336 command = "org.timestamp.down"
337 when = "timestamp"
338 [[bind]]
339 keys = "S-<right>"
340 command = "org.timestamp.day-later"
341 when = "timestamp"
342 [[bind]]
343 keys = "S-<left>"
344 command = "org.timestamp.day-earlier"
345 when = "timestamp"
346
347 """
348
349 /// Standard Mac text keys stay as they are; org commands use Control-Command chords, which
350 /// macOS text editing leaves free.
351 static let macBindings = """
352 [[bind]]
353 keys = "C-s-t"
354 command = "org.todo.cycle"
355 [[bind]]
356 keys = "C-s-<up>"
357 command = "org.priority.up"
358 [[bind]]
359 keys = "C-s-<down>"
360 command = "org.priority.down"
361 [[bind]]
362 keys = "C-s-<left>"
363 command = "org.heading.promote"
364 [[bind]]
365 keys = "C-s-<right>"
366 command = "org.heading.demote"
367 [[bind]]
368 keys = "C-M-s-<left>"
369 command = "org.subtree.promote"
370 [[bind]]
371 keys = "C-M-s-<right>"
372 command = "org.subtree.demote"
373 [[bind]]
374 keys = "C-M-s-<up>"
375 command = "org.subtree.up"
376 [[bind]]
377 keys = "C-M-s-<down>"
378 command = "org.subtree.down"
379 [[bind]]
380 keys = "s-RET"
381 command = "org.heading.insert"
382 [[bind]]
383 keys = "C-s-RET"
384 command = "org.heading.insert-after-subtree"
385 [[bind]]
386 keys = "s-S-RET"
387 command = "org.heading.insert-todo"
388 [[bind]]
389 keys = "M-s-<down>"
390 command = "org.heading.next"
391 [[bind]]
392 keys = "M-s-<up>"
393 command = "org.heading.previous"
394 [[bind]]
395 keys = "C-s-q"
396 command = "org.tags.set"
397 [[bind]]
398 keys = "s-RET"
399 command = "org.item.insert"
400 when = "item"
401 [[bind]]
402 keys = "s-S-RET"
403 command = "org.item.insert-checkbox"
404 when = "item"
405 [[bind]]
406 keys = "C-s-<left>"
407 command = "org.item.outdent"
408 when = "item"
409 [[bind]]
410 keys = "C-s-<right>"
411 command = "org.item.indent"
412 when = "item"
413 [[bind]]
414 keys = "C-M-s-<left>"
415 command = "org.item.outdent-tree"
416 when = "item"
417 [[bind]]
418 keys = "C-M-s-<right>"
419 command = "org.item.indent-tree"
420 when = "item"
421 [[bind]]
422 keys = "C-M-s-<up>"
423 command = "org.item.up"
424 when = "item"
425 [[bind]]
426 keys = "C-M-s-<down>"
427 command = "org.item.down"
428 when = "item"
429 [[bind]]
430 keys = "C-s-c"
431 command = "org.checkbox.toggle"
432 [[bind]]
433 keys = "C-s-w"
434 command = "app.refile"
435 [[bind]]
436 keys = "C-s-a"
437 command = "app.archive"
438 [[bind]]
439 keys = "C-s-."
440 command = "org.timestamp.active"
441 [[bind]]
442 keys = "C-M-s-."
443 command = "org.timestamp.inactive"
444 [[bind]]
445 keys = "C-s-s"
446 command = "org.schedule"
447 [[bind]]
448 keys = "C-s-d"
449 command = "org.deadline"
450 [[bind]]
451 keys = "C-s-p"
452 command = "org.fill-paragraph"
453 [[bind]]
454 keys = "C-s-<up>"
455 command = "org.table.row-up"
456 when = "table"
457 [[bind]]
458 keys = "C-s-<down>"
459 command = "org.table.row-down"
460 when = "table"
461 [[bind]]
462 keys = "C-s-<left>"
463 command = "org.table.column-left"
464 when = "table"
465 [[bind]]
466 keys = "C-s-<right>"
467 command = "org.table.column-right"
468 when = "table"
469 [[bind]]
470 keys = "C-M-s-<right>"
471 command = "org.table.insert-column"
472 when = "table"
473 [[bind]]
474 keys = "C-M-s-<left>"
475 command = "org.table.delete-column"
476 when = "table"
477 [[bind]]
478 keys = "C-M-s-<up>"
479 command = "org.table.kill-row"
480 when = "table"
481 [[bind]]
482 keys = "C-M-s-<down>"
483 command = "org.table.insert-row"
484 when = "table"
485 [[bind]]
486 keys = "C-s--"
487 command = "org.table.insert-hline"
488 when = "table"
489 [[bind]]
490 keys = "C-s-\\\\"
491 command = "org.table.create"
492 [[bind]]
493 keys = "C-s-<up>"
494 command = "org.timestamp.up"
495 when = "timestamp"
496 [[bind]]
497 keys = "C-s-<down>"
498 command = "org.timestamp.down"
499 when = "timestamp"
500 [[bind]]
501 keys = "C-s-<right>"
502 command = "org.timestamp.day-later"
503 when = "timestamp"
504 [[bind]]
505 keys = "C-s-<left>"
506 command = "org.timestamp.day-earlier"
507 when = "timestamp"
508
509 """
510}