Sources/OrgCore/Keymap/PresetDoom.swift

524b5afe95ec3f3e3d1daba761a9e181f09cf88a
orgstar/Sources/OrgCore/Keymap/PresetDoom.swift history · blame · raw

550 lines · 15686 bytes

  1extension KeymapPreset {
  2    static var doomToml: String {
  3        var problems: [String] = []
  4        let emacs = try! Keymap(toml: common + emacsBindings, problems: &problems)
  5        let translations: [String: String] = ["<left>": "h", "<right>": "l", "<up>": "k", "<down>": "j"]
  6        var out = ""
  7        func bind(_ keys: String, _ command: String, when: String?, mode: String) {
  8            out += "[[bind]]\nkeys = \"\(keys.replacingOccurrences(of: "\\", with: "\\\\"))\"\ncommand = \"\(command)\"\n"
  9            if let when { out += "when = \"\(when)\"\n" }
 10            out += "mode = \"\(mode)\"\n"
 11        }
 12        for binding in emacs.bindings {
 13            let first = binding.keys[0]
 14            let keys = KeySequence.format(binding.keys)
 15            let orgKey = first.key == "c" && first.modifiers == [.control] || first.key == "x" && first.modifiers == [.control]
 16                || (first.modifiers.contains(.meta) && ["<left>", "<right>", "<up>", "<down>", "RET"].contains(first.key))
 17                || (first.modifiers.contains(.shift) && ["<left>", "<right>", "<up>", "<down>"].contains(first.key))
 18                || (first.modifiers == [.control] && first.key == "RET")
 19                || keys == "M-x" || keys == "M-q"
 20            guard orgKey else { continue }
 21            for mode in ["normal", "insert", "visual"] { bind(keys, binding.command, when: binding.when, mode: mode) }
 22            // evil-org: M-h/j/k/l and M-H/J/K/L in normal, visual and insert.
 23            if binding.keys.count == 1, first.modifiers.contains(.meta), let letter = translations[first.key] {
 24                let shifted = first.modifiers.contains(.shift)
 25                let key = "M-" + (shifted ? letter.uppercased() : letter)
 26                for mode in ["normal", "insert", "visual"] { bind(key, binding.command, when: binding.when, mode: mode) }
 27            }
 28            // Doom: C-S-h/j/k/l are org-shift* in normal and insert.
 29            if binding.keys.count == 1, first.modifiers == [.shift], let letter = translations[first.key] {
 30                for mode in ["normal", "insert"] { bind("C-" + letter.uppercased(), binding.command, when: binding.when, mode: mode) }
 31            }
 32            // evil-org insert state: C-t demotes, C-d promotes.
 33            if binding.keys.count == 1, first.modifiers == [.meta], first.key == "<right>" || first.key == "<left>" {
 34                bind(first.key == "<right>" ? "C-t" : "C-d", binding.command, when: binding.when, mode: "insert")
 35            }
 36        }
 37        return out + doomBindings
 38    }
 39
 40    static let doomBindings = """
 41        # Leader
 42        [[bind]]
 43        keys = "SPC SPC"
 44        command = "app.quick-open"
 45        mode = "normal"
 46        [[bind]]
 47        keys = "SPC q q"
 48        command = "app.quit"
 49        mode = "normal"
 50        [[bind]]
 51        keys = "SPC ."
 52        command = "app.quick-open"
 53        mode = "normal"
 54        [[bind]]
 55        keys = "SPC f f"
 56        command = "app.quick-open"
 57        mode = "normal"
 58        [[bind]]
 59        keys = "SPC f s"
 60        command = "app.save"
 61        mode = "normal"
 62        # Windows
 63        [[bind]]
 64        keys = "SPC w s"
 65        command = "app.split-below"
 66        mode = "normal"
 67        [[bind]]
 68        keys = "SPC w v"
 69        command = "app.split-right"
 70        mode = "normal"
 71        [[bind]]
 72        keys = "SPC w d"
 73        command = "app.pane-close"
 74        mode = "normal"
 75        [[bind]]
 76        keys = "SPC w c"
 77        command = "app.pane-close"
 78        mode = "normal"
 79        [[bind]]
 80        keys = "SPC w o"
 81        command = "app.pane-only"
 82        mode = "normal"
 83        [[bind]]
 84        keys = "SPC w w"
 85        command = "app.pane-next"
 86        mode = "normal"
 87        [[bind]]
 88        keys = "SPC w n"
 89        command = "app.window-new"
 90        mode = "normal"
 91        [[bind]]
 92        keys = "C-w s"
 93        command = "app.split-below"
 94        mode = "normal"
 95        [[bind]]
 96        keys = "C-w v"
 97        command = "app.split-right"
 98        mode = "normal"
 99        [[bind]]
100        keys = "C-w c"
101        command = "app.pane-close"
102        mode = "normal"
103        [[bind]]
104        keys = "C-w o"
105        command = "app.pane-only"
106        mode = "normal"
107        [[bind]]
108        keys = "C-w w"
109        command = "app.pane-next"
110        mode = "normal"
111        # Buffers
112        [[bind]]
113        keys = "SPC b b"
114        command = "app.buffer.switch"
115        mode = "normal"
116        [[bind]]
117        keys = "SPC b B"
118        command = "app.buffer.switch"
119        mode = "normal"
120        [[bind]]
121        keys = "SPC ,"
122        command = "app.buffer.switch"
123        mode = "normal"
124        [[bind]]
125        keys = "SPC `"
126        command = "app.buffer.last"
127        mode = "normal"
128        [[bind]]
129        keys = "SPC b k"
130        command = "app.buffer.kill"
131        mode = "normal"
132        [[bind]]
133        keys = "SPC b d"
134        command = "app.buffer.kill"
135        mode = "normal"
136        [[bind]]
137        keys = "SPC b K"
138        command = "app.buffer.kill-all"
139        mode = "normal"
140        [[bind]]
141        keys = "SPC b O"
142        command = "app.buffer.kill-others"
143        mode = "normal"
144        [[bind]]
145        keys = "SPC b n"
146        command = "app.buffer.next"
147        mode = "normal"
148        [[bind]]
149        keys = "SPC b p"
150        command = "app.buffer.previous"
151        mode = "normal"
152        [[bind]]
153        keys = "SPC b ]"
154        command = "app.buffer.next"
155        mode = "normal"
156        [[bind]]
157        keys = "SPC b ["
158        command = "app.buffer.previous"
159        mode = "normal"
160        [[bind]]
161        keys = "] b"
162        command = "app.buffer.next"
163        mode = "normal"
164        [[bind]]
165        keys = "[ b"
166        command = "app.buffer.previous"
167        mode = "normal"
168        [[bind]]
169        keys = "SPC b s"
170        command = "app.save"
171        mode = "normal"
172        [[bind]]
173        keys = "SPC b S"
174        command = "app.save-all"
175        mode = "normal"
176        [[bind]]
177        keys = "SPC s s"
178        command = "edit.find"
179        mode = "normal"
180        [[bind]]
181        keys = "SPC /"
182        command = "app.search"
183        mode = "normal"
184        [[bind]]
185        keys = "SPC s p"
186        command = "app.search"
187        mode = "normal"
188        [[bind]]
189        keys = "SPC :"
190        command = "app.palette"
191        mode = "normal"
192        [[bind]]
193        keys = "SPC o a"
194        command = "app.agenda"
195        mode = "normal"
196        [[bind]]
197        keys = "SPC X"
198        command = "app.capture"
199        mode = "normal"
200        [[bind]]
201        keys = "SPC z t"
202        command = "app.clock.report"
203        mode = "normal"
204        [[bind]]
205        keys = "SPC h r r"
206        command = "app.reload-keymap"
207        mode = "normal"
208        [[bind]]
209        keys = "SPC t s"
210        command = "editor.toggle-spell-check"
211        mode = "normal"
212        [[bind]]
213        keys = "SPC t w"
214        command = "editor.toggle-truncate-lines"
215        mode = "normal"
216
217        # Localleader (SPC m)
218        [[bind]]
219        keys = "SPC m '"
220        command = "org.edit-special"
221        mode = "normal"
222        [[bind]]
223        keys = "SPC m s c"
224        command = "org.subtree.clone"
225        mode = "normal"
226        [[bind]]
227        keys = "SPC m s d"
228        command = "org.subtree.cut"
229        mode = "normal"
230        [[bind]]
231        keys = "SPC m s S"
232        command = "org.sort"
233        mode = "normal"
234        [[bind]]
235        keys = "SPC m s n"
236        command = "org.narrow.subtree"
237        mode = "normal"
238        [[bind]]
239        keys = "SPC m s s"
240        command = "org.sparse-tree"
241        mode = "normal"
242        [[bind]]
243        keys = "SPC m s N"
244        command = "org.widen"
245        mode = "normal"
246        [[bind]]
247        keys = "SPC m ."
248        command = "org.goto"
249        mode = "normal"
250        [[bind]]
251        keys = "SPC m h"
252        command = "org.heading.toggle"
253        mode = "normal"
254        [[bind]]
255        keys = "SPC m i"
256        command = "org.item.toggle"
257        mode = "normal"
258        [[bind]]
259        keys = "SPC m l l"
260        command = "org.link.insert"
261        mode = "normal"
262        [[bind]]
263        keys = "SPC m l s"
264        command = "org.link.store"
265        mode = "normal"
266        [[bind]]
267        keys = "SPC m l i"
268        command = "org.id.store-link"
269        mode = "normal"
270        [[bind]]
271        keys = "SPC n l"
272        command = "org.link.store"
273        mode = "normal"
274        [[bind]]
275        keys = "SPC m t"
276        command = "org.todo.cycle"
277        mode = "normal"
278        [[bind]]
279        keys = "SPC m q"
280        command = "org.tags.set"
281        mode = "normal"
282        [[bind]]
283        keys = "SPC m x"
284        command = "org.checkbox.toggle"
285        mode = "normal"
286        [[bind]]
287        keys = "SPC m A"
288        command = "app.archive"
289        mode = "normal"
290        [[bind]]
291        keys = "SPC m e h h"
292        command = "app.export.html"
293        mode = "normal"
294        [[bind]]
295        keys = "SPC m e h o"
296        command = "app.export.html-open"
297        mode = "normal"
298        [[bind]]
299        keys = "SPC m e m m"
300        command = "app.export.markdown"
301        mode = "normal"
302        [[bind]]
303        keys = "SPC m e l p"
304        command = "app.export.pdf"
305        mode = "normal"
306        [[bind]]
307        keys = "SPC m d d"
308        command = "org.deadline"
309        mode = "normal"
310        [[bind]]
311        keys = "SPC m d s"
312        command = "org.schedule"
313        mode = "normal"
314        [[bind]]
315        keys = "SPC m d t"
316        command = "org.timestamp.active"
317        mode = "normal"
318        [[bind]]
319        keys = "SPC m d T"
320        command = "org.timestamp.inactive"
321        mode = "normal"
322        [[bind]]
323        keys = "SPC m r r"
324        command = "app.refile"
325        mode = "normal"
326        [[bind]]
327        keys = "SPC u SPC m r r"
328        command = "app.refile.goto"
329        mode = "normal"
330        [[bind]]
331        keys = "SPC m s r"
332        command = "app.refile"
333        mode = "normal"
334        [[bind]]
335        keys = "SPC m s A"
336        command = "app.archive"
337        mode = "normal"
338        [[bind]]
339        keys = "SPC m s a"
340        command = "org.archive.toggle-tag"
341        mode = "normal"
342        [[bind]]
343        keys = "SPC m s h"
344        command = "org.subtree.promote"
345        mode = "normal"
346        [[bind]]
347        keys = "SPC m s l"
348        command = "org.subtree.demote"
349        mode = "normal"
350        [[bind]]
351        keys = "SPC m s j"
352        command = "org.subtree.down"
353        mode = "normal"
354        [[bind]]
355        keys = "SPC m s k"
356        command = "org.subtree.up"
357        mode = "normal"
358        [[bind]]
359        keys = "SPC m c i"
360        command = "app.clock.in"
361        mode = "normal"
362        [[bind]]
363        keys = "SPC m c o"
364        command = "app.clock.out"
365        mode = "normal"
366        [[bind]]
367        keys = "SPC m c c"
368        command = "app.clock.cancel"
369        mode = "normal"
370        [[bind]]
371        keys = "SPC m c g"
372        command = "app.clock.goto"
373        mode = "normal"
374        [[bind]]
375        keys = "SPC m c G"
376        command = "app.clock.goto-recent"
377        mode = "normal"
378        [[bind]]
379        keys = "SPC m c I"
380        command = "app.clock.in-last"
381        mode = "normal"
382        [[bind]]
383        keys = "SPC m c d"
384        command = "app.clock.default"
385        mode = "normal"
386        [[bind]]
387        keys = "SPC m c r"
388        command = "app.clock.resolve"
389        mode = "normal"
390        [[bind]]
391        keys = "SPC m c R"
392        command = "app.clock.report"
393        mode = "normal"
394        [[bind]]
395        keys = "SPC m c E"
396        command = "org.effort.set"
397        mode = "normal"
398        [[bind]]
399        keys = "SPC m p p"
400        command = "org.priority.set"
401        mode = "normal"
402        [[bind]]
403        keys = "SPC m o"
404        command = "org.property.read-and-set"
405        mode = "normal"
406        [[bind]]
407        keys = "SPC m p u"
408        command = "org.priority.up"
409        mode = "normal"
410        [[bind]]
411        keys = "SPC m p d"
412        command = "org.priority.down"
413        mode = "normal"
414        [[bind]]
415        keys = "SPC m b -"
416        command = "org.table.insert-hline"
417        mode = "normal"
418        [[bind]]
419        keys = "SPC m b a"
420        command = "org.table.align"
421        mode = "normal"
422        [[bind]]
423        keys = "SPC m b r"
424        command = "org.table.recalc-all"
425        mode = "normal"
426        [[bind]]
427        keys = "SPC m b d c"
428        command = "org.table.delete-column"
429        mode = "normal"
430        [[bind]]
431        keys = "SPC m b d r"
432        command = "org.table.kill-row"
433        mode = "normal"
434        [[bind]]
435        keys = "SPC m b i c"
436        command = "org.table.insert-column"
437        mode = "normal"
438        [[bind]]
439        keys = "SPC m b i r"
440        command = "org.table.insert-row"
441        mode = "normal"
442        [[bind]]
443        keys = "SPC m b i h"
444        command = "org.table.insert-hline"
445        mode = "normal"
446
447        # evil-org and Doom's org keys
448        [[bind]]
449        keys = "TAB"
450        command = "org.cycle"
451        mode = "normal"
452        [[bind]]
453        keys = "S-TAB"
454        command = "org.cycle-global"
455        mode = "normal"
456        [[bind]]
457        keys = "RET"
458        command = "org.dwim"
459        mode = "normal"
460        [[bind]]
461        keys = "z a"
462        command = "org.fold.toggle"
463        mode = "normal"
464        [[bind]]
465        keys = "z c"
466        command = "org.fold.close"
467        mode = "normal"
468        [[bind]]
469        keys = "z o"
470        command = "org.fold.open"
471        mode = "normal"
472        [[bind]]
473        keys = "z A"
474        command = "org.cycle-global"
475        mode = "normal"
476        [[bind]]
477        keys = "g h"
478        command = "org.heading.up"
479        mode = "normal"
480        [[bind]]
481        keys = "] h"
482        command = "org.heading.forward-same-level"
483        mode = "normal"
484        [[bind]]
485        keys = "[ h"
486        command = "org.heading.backward-same-level"
487        mode = "normal"
488        [[bind]]
489        keys = "RET"
490        command = "org.table.next-row"
491        when = "table"
492        mode = "insert"
493        [[bind]]
494        keys = "TAB"
495        command = "org.cycle"
496        mode = "visual"
497        [[bind]]
498        keys = "S-TAB"
499        command = "org.cycle-global"
500        mode = "visual"
501
502        # Doom's corfu: completion-at-point in insert state.
503        [[bind]]
504        keys = "C-SPC"
505        command = "editor.complete"
506        mode = "insert"
507        [[bind]]
508        keys = "C-@"
509        command = "editor.complete"
510        mode = "insert"
511
512        # Insert state: org-cycle and org-shifttab with Doom's +org-indent-maybe-h, which
513        # demotes or promotes a heading and indents or outdents an item tree.
514        [[bind]]
515        keys = "S-TAB"
516        command = "org.cycle-global"
517        mode = "insert"
518        [[bind]]
519        keys = "TAB"
520        command = "org.table.next-field"
521        when = "table"
522        mode = "insert"
523        [[bind]]
524        keys = "S-TAB"
525        command = "org.table.previous-field"
526        when = "table"
527        mode = "insert"
528        [[bind]]
529        keys = "TAB"
530        command = "org.item.indent-tree"
531        when = "item"
532        mode = "insert"
533        [[bind]]
534        keys = "S-TAB"
535        command = "org.item.outdent-tree"
536        when = "item"
537        mode = "insert"
538        [[bind]]
539        keys = "TAB"
540        command = "org.heading.demote"
541        when = "heading"
542        mode = "insert"
543        [[bind]]
544        keys = "S-TAB"
545        command = "org.heading.promote"
546        when = "heading"
547        mode = "insert"
548
549        """
550}