Skip to content

Instantly share code, notes, and snippets.

@crcx
Forked from lsparrish/gist:575798
Created September 12, 2010 16:04
Show Gist options
  • Save crcx/576204 to your computer and use it in GitHub Desktop.
Save crcx/576204 to your computer and use it in GitHub Desktop.
chain: stringBuffer'
{{
tib variable: buffer
@buffer variable: pointer
: terminate ( - ) 0 @pointer ! ;
---reveal---
: addToBuffer ( c- ) @pointer ! pointer ++ terminate ;
: getFromBuffer ( -c ) pointer -- @pointer @ terminate ;
: endOfBuffer ( -a ) repeat @pointer dup @ 0; 2drop pointer ++ again ;
: sizeOfBuffer ( -n ) @pointer @buffer - ;
: emptyBuffer ( - ) @buffer !pointer terminate ;
: setBuffer ( a- ) !buffer emptyBuffer ;
}}
;chain
with quotes'
with stringBuffer'
with strings'
chain: tabCompletion'
{{
create completions 100 allot
completions dup !
: addCompletion completions ++ @completions ! ;
: getCompletion @completions @ completions -- ;
: numCompletions @completions completions - ;
: findCompletions
last repeat
@ 0;
dup d->name
tib getLength 0 swap getSubset
tib compare [ dup addCompletion ] ifTrue
again ;
: showCompletions
completions numCompletions
[ getCompletion d->name type space ] loop ;
: finishCompletion
numCompletions 1 =
[ getCompletion d->name tib over getLength 1+ copy endBuffer ]
[ showCompletions ] if ;
variable delimiter
: testDelimiter @delimiter = ;
: testTrigger 27 = ;
: doTrigger findCompletions finishCompletion cr tib type ;
: accept ( "- )
!delimiter emptyBuffer
repeat
key dup testDelimiter not 0; drop
dup testTrigger [ doTrigger ] [ dup emit addToBuffer ] if
again ;
}}
;chain
global with tabCompletion'
: foo 32 accept tib type ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment