]> gitweb.factorcode.org Git - factor.git/commitdiff
tools.completion: better paths-matching.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 23 Oct 2012 01:51:38 +0000 (18:51 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 23 Oct 2012 01:51:38 +0000 (18:51 -0700)
basis/tools/completion/completion.factor

index 22fec129b044a078e26b2f6a4e209e40ecdda8a7..ba8cbdf6d5d1ed247ac21a97f081dbf33449b02e 100644 (file)
@@ -2,10 +2,10 @@
 ! See http://factorcode.org/license.txt for BSD license.
 
 USING: accessors arrays assocs colors.constants combinators
-combinators.short-circuit fry io io.directories kernel locals
-make math math.order namespaces sequences sorting splitting
-strings unicode.case unicode.categories unicode.data vectors
-vocabs vocabs.hierarchy words ;
+combinators.short-circuit fry io.directories io.files
+io.files.info io.pathnames kernel locals make math math.order
+sequences sorting splitting unicode.categories unicode.data
+vectors vocabs vocabs.hierarchy ;
 
 IN: tools.completion
 
@@ -107,8 +107,23 @@ PRIVATE>
 : colors-matching ( str -- seq )
     named-colors dup zip completions ;
 
-: paths-matching ( str path -- seq )
-    directory-files dup zip completions ;
+<PRIVATE
+
+: directory-paths ( directory -- paths )
+    dup '[
+        [
+            [ _ prepend-path ]
+            [ file-info directory? [ path-separator append ] when ]
+            bi
+        ] map
+    ] with-directory-files ;
+
+PRIVATE>
+
+: paths-matching ( str -- seq )
+    dup file-directory [ ?head drop ] keep
+    dup { [ exists? ] [ file-info directory? ] } 1&&
+    [ directory-paths dup zip completions ] [ 2drop { } ] if ;
 
 <PRIVATE
 
@@ -150,3 +165,5 @@ PRIVATE>
 : complete-CHAR:? ( tokens -- ? ) "CHAR:" complete-token? ;
 
 : complete-COLOR:? ( tokens -- ? ) "COLOR:" complete-token? ;
+
+: complete-P"? ( tokens -- ? ) "P\"" complete-token? ;