Created
October 15, 2012 21:54
-
-
Save lsparrish/3895813 to your computer and use it in GitHub Desktop.
prefix-based keybindings in retro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
needs struct' | |
with struct' | |
chain: binding' | |
{ | |
1 field .link | |
1 field .label | |
1 field .xt | |
} bind | |
variables| prefix lastbinding | | |
: getc:internal ( -c ) &getc 2 + @ do ; | |
: :bind ( ac- ) | |
@lastbinding &bind clone dup lastbinding !.link !.link | |
@lastbinding !.label @lastbinding !.xt ; | |
: bind: ( a"- ) getc :bind ; | |
[ over tib == | |
[ dup @prefix == | |
[ drop getc:internal | |
lastbinding [ @ dup 0 == [ drop -1 ] | |
[ 2over .label @ == [ nip .xt @ dip 32 -1 ] [ 0 ] if ] if ] until | |
] ifTrue | |
] ifTrue | |
] is remapKeys | |
&words bind: w | |
&bye bind: b | |
&.s bind: s | |
[ getc dup !prefix "The prefix is: " puts putc | |
] bind: p | |
[ "Enter a word: " puts &' do | |
"Press a key: " puts getc dup putc :bind ] bind: k | |
32 !prefix | |
;chain | |
without |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment