This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.janet
82 lines (62 loc) · 1.56 KB
/
state.janet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# XXX: this shadows a janet built-in
(var quit false)
(var gb-binds nil)
(var quit-hook nil)
(def freja-dir @"")
(var initial-file nil)
(def open-files @{})
(var eval-results nil)
(def focus @{})
(def keys-down @{})
(def out @"")
(def err @"")
(def editor-state @{})
(var user-env (make-env))
(def editor-components @{})
(def editor-state-creators @{})
(defn ext->editor
[ext &opt data]
(default ext
(do
(print "no ext provided, defaulting to .janet")
".janet"))
(def compo (get editor-components ext))
(default compo
(do
(printf "no component found for %s, defaulting to .janet" ext)
(editor-components ".janet")))
(def state-creator (get editor-state-creators ext))
(default state-creator
(do
(printf "no state-creator found for %s, defaulting to .janet" ext)
(editor-state-creators ".janet")))
#
[(compo data) (state-creator data)])
(defn add-ext-handling
[ext component creator]
(put editor-components ext component)
(put editor-state-creators ext creator))
(defn push-buffer-stack
[o]
(def new-stack
(-> (filter |(not= o $) (editor-state :stack))
(array/push o)))
(-> editor-state
(put :stack new-stack)
(put :event/changed true)))
(defn remove-buffer-stack
[o]
(def new-stack
(filter |(not= o $) (editor-state :stack)))
(-> editor-state
(put :stack new-stack)
(put :event/changed true)))
(defn focus!
``
Sets global focus to x.
``
[x]
(-> focus
(put :last-focus (focus :focus))
(put :focus x)
(put :event/changed true)))