express keymap bindings as [command-name args]

instead of using functions directly. This is so that the
appropriate frame-relevant commander can be used to execure
the command, but also makes the keymaps a little less opaque
This commit is contained in:
2022-12-26 16:53:41 +00:00
parent a5612fce2a
commit dd139c9796
4 changed files with 39 additions and 33 deletions
+17 -14
View File
@@ -26,13 +26,17 @@
(bor m (. Gdk.ModifierType k)))]
(spec->index {:keyval event.keyval : modmask})))
(fn designates-command? [tbl]
;; a keymap entry has a string as key, a command
;; definition is a numerically-indexed array
(if (. tbl 1) true))
(fn compile-keymap [input]
(collect [k v (pairs input)]
(let [f (-> k keychord->spec spec->index)]
(match (type v)
"function" (values f v)
"table" (values f (compile-keymap v))))))
(if (designates-command? v)
(values f v)
(values f (compile-keymap v))))))
(fn recogniser [source-keymap]
(let [keymap (compile-keymap source-keymap)]
@@ -42,18 +46,17 @@
(fn [_ e]
(let [c (event->index e)
v (. m c)]
(match (type v)
"table" (do
(set m v)
(values nil (.. c " ")))
"function" (do
(set m keymap)
v)
"nil" (do
(if v
(if (designates-command? v)
(do
(set m keymap)
(values nil (.. "No binding for " (view e) " ")))
)))
v)
(do
(set m v)
(values nil (.. c " "))))
(do
(set m keymap)
(values nil (.. "No binding for " (view e) " "))))))
}))