Skip to content

Instantly share code, notes, and snippets.

@lsparrish
Created October 21, 2012 02:26
Show Gist options
  • Save lsparrish/3925497 to your computer and use it in GitHub Desktop.
Save lsparrish/3925497 to your computer and use it in GitHub Desktop.
chain: keymap'
{{
( useful things: )
( internal -- ignore the vector on a word )
: internal getToken find [ @d->xt ] ifTrue 2 + , ; compile-only
( latest -- use the last defined version of a word with a given name )
: latest getToken keepString 1 , , [ find [ @d->xt ] ifTrue ] , ; compile-only
: isPrefix dup latest keymap:PREFIX @ == ;
: mkey internal getc dup putc latest keymap:TABLE + ;
---reveal---
: new:table "keymap:TABLE" header 256 allot ;
: new:prefix "keymap:PREFIX" header , ;
: bkey ' mkey ! ;
[ isPrefix
[ latest onPrefix do mkey @ dup 0 <> [ do ] ifTrue ] ifTrue
] is remapKeys
}}
;chain
chain: mykeymap'
^keymap'new:table
^keymap'bkey words w
;chain
chain: myprefixes'
9 ^keymap'new:prefix
: onPrefix "Was prefix!" puts ;
;chain
with mykeymap' with myprefixes'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment