Created
December 2, 2009 05:35
-
-
Save lsparrish/246972 to your computer and use it in GitHub Desktop.
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
{{ | |
: (`) | |
dup 0 !if literal, which @ d->class @ compile ;then | |
drop tib >number literal, ['] .data compile ; | |
---reveal--- | |
: '' ; immediate | |
: `` repeat ' dup ['] '' =if drop ;then (`) again ; immediate | |
}} | |
: :: ( -a ) here ] ; | |
: vars for variable next ; | |
: stub ( "- ) create 0 , 0 , 9 , ['] .word last @ d->class ! ; | |
: stubs ( n"- ) for stub next ; | |
4 stubs hook cursor scan-for-esc insert | |
4 stubs up down left right | |
: default: ( "- ) | |
' drop which @ d->xt @ 2 + compile ; immediate | |
:: ( -c ) | |
default: key dup 27 =if drop 32 ['] hook ['] key :is then ; | |
is scan-for-esc | |
' scan-for-esc is key | |
: char: ( "-n ) 32 accept tib @ .data ; immediate | |
:: default: key | |
cursor | |
dup 27 =if ['] scan-for-esc ['] key :is then | |
dup char: i =if ia then | |
drop 32 ; | |
is hook | |
: assign: ` dup ` char: ` =if ' which @ d->class @ execute ` then ; immediate | |
:: ( n- ) | |
assign: h left | |
assign: j down | |
assign: k up | |
assign: l right | |
assign: i insert ; | |
is cursor | |
3 vars x y insmode | |
stub hook | |
:: x -- hook ; is left | |
:: x ++ hook ; is right | |
:: y -- hook ; is up | |
:: y ++ hook ; is down | |
:: insmode @ if insmode off ;then insmode on ; is insert | |
: get-pos ( -a ) x @ y @ (line) + ; | |
:: ( - ) 43 get-pos ! v ; is hook | |
:: ( - ) get-pos dup . 32 emit @ cr ; is hook | |
:: ( - ) get-pos 0 (line) - . ; is hook | |
2 vars prior-pos prior-value | |
insmode on | |
:: ( - ) prior-pos @ | |
get-pos prior-pos ! ( save position before we write to it) | |
get-pos @ prior-value ! | |
43 get-pos ! ( write to the position ) | |
insmode @ if | |
prior-value @ swap ! ( restore prior value ) | |
then | |
v ; is hook | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment