Overhaul and add tests to keymap code

Overhaul the keymap code and add a bunch of tests.
The main new feature is the introduction of the KeyAlias type,
which allows for lazy redirection as opposed to the eager
redirection originally implemented. At some point down the road
the redirection scheme changed to a hybrid scheme where the
redirection would look in all the layers passed to `keymap`
at the same time (rather than just the layer it is specified at
and any layers below it). Unfortunately this is also quite
incompatible with adding new keymaps dynamically on top of the
existing layer. Since this behavior is useful for taking care of
canonicalization of escape sequences, the KeyAlias type is added
to support this use case. A key sequence mapped to a KeyAlias("ZZZ")
will behave as if ZZZ had been typed instead.

@blakejohnson, I'd appreciate if you could have a look to see if this looks sensible to you.