Skip to content

Instantly share code, notes, and snippets.

@crcx
Forked from lsparrish/more.rx
Created October 18, 2012 19:45
Show Gist options
  • Save crcx/3914368 to your computer and use it in GitHub Desktop.
Save crcx/3914368 to your computer and use it in GitHub Desktop.
yet another approach
( useful things )
: dictionary.find/xt ( string:name - xt ) find [ @d->xt ] [ drop #0 ] if ;
: getc:internal ( -c ) &getc 2 + @ do ;
( keymap )
9 variable: prefix:CHAR
create prefix:TABLE 256 allot
( We will lookup the keymap by name, to allow for per-application maps )
[ dup @prefix:CHAR ==
[ drop getc:internal
"prefix:TABLE" dictionary.find/xt + @ dup 0 <>
[ dip cr ] [ drop ] if 0
] ifTrue
dup '| ==
[ drop getc:internal dup putc space "prefix:TABLE" dictionary.find/xt + &' do swap ! cr 0 ] ifTrue
] is remapKeys
: prefix:tab 09 !prefix:CHAR ;
: prefix:space 32 !prefix:CHAR ;
: (matching) ;
: bindTo: ( quote "character" - )
getc "prefix:TABLE" dictionary.find/xt + ! ;
[ cr
"? help text\n" puts
"d<word> documentation for word\n" puts
"s show stack contents\n" puts
"p<char> change trigger character to <char>\n" puts ] bindTo: ?
[ "display docs for: " puts
getToken find [ cr @d->doc 0; puts ] [ drop cr "no docs found!" puts ] if ] bindTo: d
[ "display functions matching: " puts
getToken cr (matching) ] bindTo: m
[ getc:internal dup putc !prefix:CHAR ] bindTo: p
|wwords
|s.s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment