unnest conditionals in keymap recogniser
This commit is contained in:
parent
ec391a9e57
commit
39735be891
39
keymap.fnl
39
keymap.fnl
@ -44,17 +44,20 @@
|
||||
(bor m (. Gdk.ModifierType k)))]
|
||||
(spec->index {:keyval event.keyval : modmask})))
|
||||
|
||||
(fn designates-command? [tbl]
|
||||
(fn command? [tbl]
|
||||
;; a keymap entry has a string as key, a command
|
||||
;; definition is a numerically-indexed array
|
||||
(if (. tbl 1) true))
|
||||
|
||||
(fn keymap? [tbl]
|
||||
(not (. tbl 1)))
|
||||
|
||||
(fn compile-keymap [input]
|
||||
(collect [k v (pairs input)]
|
||||
(let [f (-> k keychord->spec spec->index)]
|
||||
(if (designates-command? v)
|
||||
(values f v)
|
||||
(values f (compile-keymap v))))))
|
||||
(if (keymap? v)
|
||||
(values f (compile-keymap v))
|
||||
(values f v)))))
|
||||
|
||||
(fn recogniser [source-keymap]
|
||||
(let [keymap (compile-keymap source-keymap)]
|
||||
@ -63,19 +66,21 @@
|
||||
:accept-event
|
||||
(fn [_ e]
|
||||
(when (not (modifier? e.keyval))
|
||||
(let [c (event->index e)
|
||||
v (. m c)]
|
||||
(if v
|
||||
(if (designates-command? v)
|
||||
(do
|
||||
(set m keymap)
|
||||
v)
|
||||
(do
|
||||
(set m v)
|
||||
(values nil (.. c " "))))
|
||||
(do
|
||||
(set m keymap)
|
||||
(values nil (.. "No binding for " (view e) " ")))))))
|
||||
(let [c (event->index e)]
|
||||
(match (. m c)
|
||||
(where v (keymap? v))
|
||||
(do
|
||||
(set m v)
|
||||
(values nil (.. c " ")))
|
||||
|
||||
(where v (command? v))
|
||||
(do
|
||||
(set m keymap)
|
||||
v)
|
||||
_
|
||||
(do
|
||||
(set m keymap)
|
||||
(values nil (.. "No binding for " (view e) " ")))))))
|
||||
}))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user