]> gitweb.factorcode.org Git - factor.git/commitdiff
readline-listener: change matching to use prefixed.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 25 Sep 2012 16:37:50 +0000 (09:37 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 25 Sep 2012 16:37:50 +0000 (09:37 -0700)
extra/readline-listener/readline-listener.factor
extra/readline/ffi/ffi.factor

index 155a209907df3579a4cff903ed355906ac090243..cd7e0070a7bd0e0dbbcf13d66b02ee341f99d004 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2011 Erik Charlebois.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs combinators io kernel listener readline
-sequences splitting threads tools.completion ;
+USING: accessors assocs colors.constants combinators fry io
+kernel listener readline sequences splitting threads
+tools.completion unicode.data vocabs vocabs.hierarchy ;
 IN: readline-listener
 
 <PRIVATE
@@ -21,14 +22,29 @@ M: readline-reader prompt.
 : clear-completions ( -- )
     f completions tset ;
 
+: prefixed ( prefix seq -- seq' )
+    swap '[ _ head? ] filter ;
+
+: prefixed-words ( prefix -- words )
+    all-words [ name>> ] map! prefixed ;
+
+: prefixed-vocabs ( prefix -- vocabs )
+    all-vocabs-recursive filter-vocabs [ name>> ] map! prefixed ;
+
+: prefixed-colors ( prefix -- colors )
+    named-colors prefixed ;
+
+: prefixed-chars ( prefix -- chars )
+    name-map keys prefixed ;
+
 : get-completions ( prefix -- completions )
     completions tget [ nip ] [
         current-line " \r\n" split {
-            { [ dup complete-vocab? ] [ drop vocabs-matching ] }
-            { [ dup complete-CHAR:? ] [ drop chars-matching ] }
-            { [ dup complete-COLOR:? ] [ drop colors-matching ] }
-            [ drop words-matching ]
-        } cond values dup completions tset
+            { [ dup complete-vocab? ] [ drop prefixed-vocabs ] }
+            { [ dup complete-CHAR:? ] [ drop prefixed-chars ] }
+            { [ dup complete-COLOR:? ] [ drop prefixed-colors ] }
+            [ drop prefixed-words ]
+        } cond dup completions tset
     ] if* ;
 
 PRIVATE>
index c40c1e31277ef627c63e7ef4acca1a604d9e6564..593da687b33fabebcd5c8e7d8271c27794552e8b 100644 (file)
@@ -21,7 +21,8 @@ STRUCT: HIST_ENTRY
     { timestamp c-string   }
     { data      histdata_t } ;
 
-: HISTENT_BYTES ( hs -- n ) [ line>> strlen ] [ timestamp>> strlen ] bi + ; inline
+: HISTENT_BYTES ( hs -- n )
+    [ line>> strlen ] [ timestamp>> strlen ] bi + ; inline
 
 STRUCT: HISTORY_STATE
     { entries HIST_ENTRY** }