Add vocab completion for readline when line begins with USING:
parent
b9e18184c6
commit
c492ff62a7
|
@ -2,24 +2,14 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien.data fry io io.encodings.utf8 kernel
|
USING: accessors alien.data fry io io.encodings.utf8 kernel
|
||||||
listener namespaces readline sequences threads vocabs
|
listener namespaces readline sequences threads vocabs
|
||||||
command-line ;
|
command-line vocabs.hierarchy sequences.deep locals
|
||||||
|
splitting math ;
|
||||||
QUALIFIED: readline.ffi
|
QUALIFIED: readline.ffi
|
||||||
IN: readline-listener
|
IN: readline-listener
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
SYMBOL: completions
|
SYMBOL: completions
|
||||||
|
|
||||||
: prefixed-words ( prefix -- words )
|
|
||||||
'[ name>> _ head? ] all-words swap filter [ name>> ] map ;
|
|
||||||
|
|
||||||
: clear-completions ( -- )
|
|
||||||
f completions tset ;
|
|
||||||
|
|
||||||
: get-completions ( prefix -- completions )
|
|
||||||
completions tget dup [ nip ] [ drop
|
|
||||||
prefixed-words dup completions tset
|
|
||||||
] if ;
|
|
||||||
|
|
||||||
TUPLE: readline-reader { prompt initial: f } ;
|
TUPLE: readline-reader { prompt initial: f } ;
|
||||||
M: readline-reader stream-readln
|
M: readline-reader stream-readln
|
||||||
flush [ prompt>> dup [ " " append ] [ ] if readline ]
|
flush [ prompt>> dup [ " " append ] [ ] if readline ]
|
||||||
|
@ -27,6 +17,31 @@ M: readline-reader stream-readln
|
||||||
|
|
||||||
M: readline-reader prompt.
|
M: readline-reader prompt.
|
||||||
>>prompt drop ;
|
>>prompt drop ;
|
||||||
|
|
||||||
|
: word-names ( -- strs )
|
||||||
|
all-words [ name>> ] map ;
|
||||||
|
|
||||||
|
: vocab-names ( -- strs )
|
||||||
|
all-vocabs-recursive no-roots no-prefixes [ name>> ] map ;
|
||||||
|
|
||||||
|
: prefixed-words ( prefix -- words )
|
||||||
|
'[ _ head? ] word-names swap filter ;
|
||||||
|
|
||||||
|
: prefixed-vocabs ( prefix -- words )
|
||||||
|
'[ _ head? ] vocab-names swap filter ;
|
||||||
|
|
||||||
|
: clear-completions ( -- )
|
||||||
|
f completions tset ;
|
||||||
|
|
||||||
|
: get-completions ( prefix -- completions )
|
||||||
|
completions tget dup [ nip ] [
|
||||||
|
drop current-line " " split first
|
||||||
|
"USING:" = [
|
||||||
|
prefixed-vocabs
|
||||||
|
] [
|
||||||
|
prefixed-words
|
||||||
|
] if dup completions tset
|
||||||
|
] if ;
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: readline-listener ( -- )
|
: readline-listener ( -- )
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.strings destructors io.encodings.utf8 kernel libc
|
USING: alien.strings destructors io.encodings.utf8 kernel libc
|
||||||
sequences macros quotations words compiler.units fry
|
sequences macros quotations words compiler.units fry
|
||||||
alien.data ;
|
alien.data alien.libraries ;
|
||||||
QUALIFIED: readline.ffi
|
QUALIFIED: readline.ffi
|
||||||
IN: readline
|
IN: readline
|
||||||
|
|
||||||
|
@ -15,6 +15,12 @@ IN: readline
|
||||||
] [ f ] if*
|
] [ f ] if*
|
||||||
] with-destructors ;
|
] with-destructors ;
|
||||||
|
|
||||||
|
: current-line ( -- str )
|
||||||
|
readline.ffi:rl_line_buffer ;
|
||||||
|
|
||||||
|
: has-readline ( -- ? )
|
||||||
|
"readline" dup load-library dlsym-raw >boolean ;
|
||||||
|
|
||||||
MACRO: set-completion ( quot -- )
|
MACRO: set-completion ( quot -- )
|
||||||
[
|
[
|
||||||
'[ @ [ utf8 malloc-string ] [ f ] if* ]
|
'[ @ [ utf8 malloc-string ] [ f ] if* ]
|
||||||
|
|
Loading…
Reference in New Issue