Sources/OrgCore/Keymap/Presets.swift
413 lines · 10746 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
36 """
37
38 static let emacsBindings = """
39 # Movement and editing. With a mark set (C-SPC), movement extends the region.
40 [[bind]]
41 keys = "C-f"
42 command = "edit.forward-char"
43 [[bind]]
44 keys = "C-b"
45 command = "edit.backward-char"
46 [[bind]]
47 keys = "C-n"
48 command = "edit.next-line"
49 [[bind]]
50 keys = "C-p"
51 command = "edit.previous-line"
52 [[bind]]
53 keys = "C-a"
54 command = "edit.beginning-of-line"
55 [[bind]]
56 keys = "C-e"
57 command = "edit.end-of-line"
58 [[bind]]
59 keys = "M-f"
60 command = "edit.forward-word"
61 [[bind]]
62 keys = "M-b"
63 command = "edit.backward-word"
64 [[bind]]
65 keys = "M-<"
66 command = "edit.beginning-of-buffer"
67 [[bind]]
68 keys = "M->"
69 command = "edit.end-of-buffer"
70 [[bind]]
71 keys = "C-v"
72 command = "edit.scroll-up"
73 [[bind]]
74 keys = "M-v"
75 command = "edit.scroll-down"
76 [[bind]]
77 keys = "C-l"
78 command = "edit.recenter"
79 [[bind]]
80 keys = "C-d"
81 command = "edit.delete-char"
82 [[bind]]
83 keys = "M-d"
84 command = "edit.kill-word"
85 [[bind]]
86 keys = "M-DEL"
87 command = "edit.backward-kill-word"
88 [[bind]]
89 keys = "C-k"
90 command = "edit.kill-line"
91 [[bind]]
92 keys = "C-y"
93 command = "edit.yank"
94 [[bind]]
95 keys = "C-SPC"
96 command = "edit.set-mark"
97 [[bind]]
98 keys = "C-x h"
99 command = "edit.select-all"
100 [[bind]]
101 keys = "C-w"
102 command = "edit.kill-region"
103 [[bind]]
104 keys = "M-w"
105 command = "edit.copy-region"
106 [[bind]]
107 keys = "C-/"
108 command = "edit.undo"
109 [[bind]]
110 keys = "C-_"
111 command = "edit.undo"
112 [[bind]]
113 keys = "C-x u"
114 command = "edit.undo"
115 [[bind]]
116 keys = "C-g"
117 command = "edit.keyboard-quit"
118 [[bind]]
119 keys = "C-t"
120 command = "edit.transpose-chars"
121 [[bind]]
122 keys = "C-s"
123 command = "edit.find"
124 [[bind]]
125 keys = "C-r"
126 command = "edit.find"
127
128 # Files and commands
129 [[bind]]
130 keys = "C-x C-s"
131 command = "app.save"
132 [[bind]]
133 keys = "C-x C-f"
134 command = "app.quick-open"
135 [[bind]]
136 keys = "C-x b"
137 command = "app.quick-open"
138 [[bind]]
139 keys = "M-x"
140 command = "app.palette"
141
142 # Org
143 [[bind]]
144 keys = "C-c C-t"
145 command = "org.todo.cycle"
146 [[bind]]
147 keys = "S-<right>"
148 command = "org.todo.cycle"
149 when = "heading"
150 [[bind]]
151 keys = "S-<up>"
152 command = "org.priority.up"
153 when = "heading"
154 [[bind]]
155 keys = "S-<down>"
156 command = "org.priority.down"
157 when = "heading"
158 [[bind]]
159 keys = "M-<left>"
160 command = "org.heading.promote"
161 when = "heading"
162 [[bind]]
163 keys = "M-<right>"
164 command = "org.heading.demote"
165 when = "heading"
166 [[bind]]
167 keys = "M-S-<left>"
168 command = "org.subtree.promote"
169 when = "heading"
170 [[bind]]
171 keys = "M-S-<right>"
172 command = "org.subtree.demote"
173 when = "heading"
174 [[bind]]
175 keys = "M-<up>"
176 command = "org.subtree.up"
177 when = "heading"
178 [[bind]]
179 keys = "M-<down>"
180 command = "org.subtree.down"
181 when = "heading"
182 [[bind]]
183 keys = "M-RET"
184 command = "org.heading.insert"
185 [[bind]]
186 keys = "C-RET"
187 command = "org.heading.insert-after-subtree"
188 [[bind]]
189 keys = "M-S-RET"
190 command = "org.heading.insert-todo"
191 [[bind]]
192 keys = "C-c C-n"
193 command = "org.heading.next"
194 [[bind]]
195 keys = "C-c C-p"
196 command = "org.heading.previous"
197 [[bind]]
198 keys = "C-c C-f"
199 command = "org.heading.forward-same-level"
200 [[bind]]
201 keys = "C-c C-b"
202 command = "org.heading.backward-same-level"
203 [[bind]]
204 keys = "C-c C-u"
205 command = "org.heading.up"
206 [[bind]]
207 keys = "C-c C-q"
208 command = "org.tags.set"
209 [[bind]]
210 keys = "M-RET"
211 command = "org.item.insert"
212 when = "item"
213 [[bind]]
214 keys = "M-S-RET"
215 command = "org.item.insert-checkbox"
216 when = "item"
217 [[bind]]
218 keys = "M-<left>"
219 command = "org.item.outdent"
220 when = "item"
221 [[bind]]
222 keys = "M-<right>"
223 command = "org.item.indent"
224 when = "item"
225 [[bind]]
226 keys = "M-S-<left>"
227 command = "org.item.outdent-tree"
228 when = "item"
229 [[bind]]
230 keys = "M-S-<right>"
231 command = "org.item.indent-tree"
232 when = "item"
233 [[bind]]
234 keys = "M-<up>"
235 command = "org.item.up"
236 when = "item"
237 [[bind]]
238 keys = "M-<down>"
239 command = "org.item.down"
240 when = "item"
241 [[bind]]
242 keys = "C-c C-c"
243 command = "org.checkbox.toggle"
244 when = "item"
245 [[bind]]
246 keys = "C-c C-x C-b"
247 command = "org.checkbox.toggle"
248 [[bind]]
249 keys = "C-c C-w"
250 command = "app.refile"
251 [[bind]]
252 keys = "C-c C-x C-s"
253 command = "app.archive"
254 [[bind]]
255 keys = "C-c $"
256 command = "app.archive"
257 [[bind]]
258 keys = "C-c ."
259 command = "org.timestamp.active"
260 [[bind]]
261 keys = "C-c !"
262 command = "org.timestamp.inactive"
263 [[bind]]
264 keys = "C-c C-s"
265 command = "org.schedule"
266 [[bind]]
267 keys = "C-c C-d"
268 command = "org.deadline"
269 [[bind]]
270 keys = "M-q"
271 command = "org.fill-paragraph"
272 [[bind]]
273 keys = "S-<up>"
274 command = "org.timestamp.up"
275 when = "timestamp"
276 [[bind]]
277 keys = "S-<down>"
278 command = "org.timestamp.down"
279 when = "timestamp"
280 [[bind]]
281 keys = "S-<right>"
282 command = "org.timestamp.day-later"
283 when = "timestamp"
284 [[bind]]
285 keys = "S-<left>"
286 command = "org.timestamp.day-earlier"
287 when = "timestamp"
288
289 """
290
291 /// Standard Mac text keys stay as they are; org commands use Control-Command chords, which
292 /// macOS text editing leaves free.
293 static let macBindings = """
294 [[bind]]
295 keys = "C-s-t"
296 command = "org.todo.cycle"
297 [[bind]]
298 keys = "C-s-<up>"
299 command = "org.priority.up"
300 [[bind]]
301 keys = "C-s-<down>"
302 command = "org.priority.down"
303 [[bind]]
304 keys = "C-s-<left>"
305 command = "org.heading.promote"
306 [[bind]]
307 keys = "C-s-<right>"
308 command = "org.heading.demote"
309 [[bind]]
310 keys = "C-M-s-<left>"
311 command = "org.subtree.promote"
312 [[bind]]
313 keys = "C-M-s-<right>"
314 command = "org.subtree.demote"
315 [[bind]]
316 keys = "C-M-s-<up>"
317 command = "org.subtree.up"
318 [[bind]]
319 keys = "C-M-s-<down>"
320 command = "org.subtree.down"
321 [[bind]]
322 keys = "s-RET"
323 command = "org.heading.insert"
324 [[bind]]
325 keys = "C-s-RET"
326 command = "org.heading.insert-after-subtree"
327 [[bind]]
328 keys = "s-S-RET"
329 command = "org.heading.insert-todo"
330 [[bind]]
331 keys = "M-s-<down>"
332 command = "org.heading.next"
333 [[bind]]
334 keys = "M-s-<up>"
335 command = "org.heading.previous"
336 [[bind]]
337 keys = "C-s-q"
338 command = "org.tags.set"
339 [[bind]]
340 keys = "s-RET"
341 command = "org.item.insert"
342 when = "item"
343 [[bind]]
344 keys = "s-S-RET"
345 command = "org.item.insert-checkbox"
346 when = "item"
347 [[bind]]
348 keys = "C-s-<left>"
349 command = "org.item.outdent"
350 when = "item"
351 [[bind]]
352 keys = "C-s-<right>"
353 command = "org.item.indent"
354 when = "item"
355 [[bind]]
356 keys = "C-M-s-<left>"
357 command = "org.item.outdent-tree"
358 when = "item"
359 [[bind]]
360 keys = "C-M-s-<right>"
361 command = "org.item.indent-tree"
362 when = "item"
363 [[bind]]
364 keys = "C-M-s-<up>"
365 command = "org.item.up"
366 when = "item"
367 [[bind]]
368 keys = "C-M-s-<down>"
369 command = "org.item.down"
370 when = "item"
371 [[bind]]
372 keys = "C-s-c"
373 command = "org.checkbox.toggle"
374 [[bind]]
375 keys = "C-s-w"
376 command = "app.refile"
377 [[bind]]
378 keys = "C-s-a"
379 command = "app.archive"
380 [[bind]]
381 keys = "C-s-."
382 command = "org.timestamp.active"
383 [[bind]]
384 keys = "C-M-s-."
385 command = "org.timestamp.inactive"
386 [[bind]]
387 keys = "C-s-s"
388 command = "org.schedule"
389 [[bind]]
390 keys = "C-s-d"
391 command = "org.deadline"
392 [[bind]]
393 keys = "C-s-p"
394 command = "org.fill-paragraph"
395 [[bind]]
396 keys = "C-s-<up>"
397 command = "org.timestamp.up"
398 when = "timestamp"
399 [[bind]]
400 keys = "C-s-<down>"
401 command = "org.timestamp.down"
402 when = "timestamp"
403 [[bind]]
404 keys = "C-s-<right>"
405 command = "org.timestamp.day-later"
406 when = "timestamp"
407 [[bind]]
408 keys = "C-s-<left>"
409 command = "org.timestamp.day-earlier"
410 when = "timestamp"
411
412 """
413}