]> gitweb.factorcode.org Git - factor.git/commitdiff
tools.completion: adding EDITOR: tab completion
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 5 Apr 2023 22:33:56 +0000 (15:33 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 5 Apr 2023 22:33:56 +0000 (15:33 -0700)
basis/tools/completion/completion.factor
basis/ui/tools/listener/completion/completion.factor
extra/readline-listener/readline-listener.factor

index 4cc3aa6208dbe47d46bcffacfc395341db356c4d..080e17b639c2b5ae0d3cf9b9459e7164c7f3206f 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2005, 2009 Slava Pestov.
 ! See https://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs colors combinators
-combinators.short-circuit io.directories io.files io.files.info
-io.pathnames kernel make math math.order sequences
+combinators.short-circuit editors io.directories io.files
+io.files.info io.pathnames kernel make math math.order sequences
 sequences.private sorting splitting splitting.monotonic unicode
 unicode.data vocabs vocabs.hierarchy ;
 IN: tools.completion
@@ -102,6 +102,9 @@ PRIVATE>
 : colors-matching ( str -- seq )
     named-colors dup zip completions ;
 
+: editors-matching ( str -- seq )
+    available-editors [ "editors." ?head drop ] map dup zip completions ;
+
 : strings-matching ( str seq -- seq' )
     dup zip completions keys ;
 
@@ -176,6 +179,8 @@ PRIVATE>
 
 : complete-color? ( tokens -- ? ) "COLOR:" complete-token? ;
 
+: complete-editor? ( tokens -- ? ) "EDITOR:" complete-token? ;
+
 <PRIVATE
 
 : complete-string? ( tokens token -- ? )
index 91cc1a50fad4a3656bec12b315f446c12b8c548e..8073277d92a920464ad2b9f316a777343fe4923b 100644 (file)
@@ -34,11 +34,12 @@ TUPLE: vocab-word-completion vocab-name ;
 C: <vocab-word-completion> vocab-word-completion
 
 SINGLETONS: vocab-completion color-completion char-completion
-path-completion history-completion ;
+editor-completion path-completion history-completion ;
 UNION: definition-completion word-completion
 vocab-word-completion vocab-completion ;
 UNION: code-completion definition-completion
-color-completion char-completion path-completion ;
+color-completion char-completion editor-completion
+path-completion ;
 UNION: listener-completion code-completion history-completion ;
 
 GENERIC: completion-quot ( interactor completion-mode -- quot )
@@ -50,6 +51,7 @@ M: word-completion completion-quot [ words-matching ] (completion-quot) ;
 M: vocab-word-completion completion-quot nip vocab-name>> '[ _ vocab-words-matching ] ;
 M: vocab-completion completion-quot [ vocabs-matching ] (completion-quot) ;
 M: color-completion completion-quot [ colors-matching ] (completion-quot) ;
+M: editor-completion completion-quot [ editors-matching ] (completion-quot) ;
 M: char-completion completion-quot [ chars-matching ] (completion-quot) ;
 M: path-completion completion-quot [ paths-matching ] (completion-quot) ;
 M: history-completion completion-quot drop '[ _ history-completions ] ;
@@ -65,6 +67,7 @@ M: word-completion completion-banner drop "Words" ;
 M: vocab-word-completion completion-banner drop "Words" ;
 M: vocab-completion completion-banner drop "Vocabularies" ;
 M: color-completion completion-banner drop "Colors" ;
+M: editor-completion completion-banner drop "Editors" ;
 M: char-completion completion-banner drop "Unicode code point names" ;
 M: path-completion completion-banner drop "Paths" ;
 M: history-completion completion-banner drop "Input history" ;
@@ -109,6 +112,7 @@ M: color-completion row-color
         { [ dup complete-vocab? ] [ 2drop vocab-completion ] }
         { [ dup complete-char? ] [ 2drop char-completion ] }
         { [ dup complete-color? ] [ 2drop color-completion ] }
+        { [ dup complete-editor? ] [ 2drop editor-completion ] }
         { [ dup complete-pathname? ] [ 2drop path-completion ] }
         { [ dup complete-vocab-words? ] [ nip harvest second <vocab-word-completion> ] }
         [ drop <word-completion> ]
index 321470ae62c438947befb632584bde707c87dcfe..0e22c91f1da4189cc355d3384480c2d6bb9c6aa2 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2011 Erik Charlebois.
 ! See https://factorcode.org/license.txt for BSD license.
 
-USING: accessors assocs colors combinators io kernel listener
-readline sequences sets splitting threads tools.completion
-unicode.data vocabs vocabs.hierarchy ;
+USING: accessors assocs colors combinators editors io kernel
+listener readline sequences sets splitting threads
+tools.completion unicode.data vocabs vocabs.hierarchy ;
 
 IN: readline-listener
 
@@ -40,6 +40,9 @@ M: readline-reader prompt.
 : prefixed-colors ( prefix -- colors )
     named-colors prefixed ;
 
+: prefixed-editors ( prefix -- editors )
+    available-editors [ "editors." ?head drop ] map prefixed ;
+
 : prefixed-chars ( prefix -- chars )
     name-map keys prefixed ;
 
@@ -52,6 +55,7 @@ M: readline-reader prompt.
             { [ dup complete-vocab? ] [ drop prefixed-vocabs ] }
             { [ dup complete-char? ] [ drop prefixed-chars ] }
             { [ dup complete-color? ] [ drop prefixed-colors ] }
+            { [ dup complete-editor? ] [ drop prefixed-editors ] }
             { [ dup complete-pathname? ] [ drop prefixed-paths ] }
             { [ dup complete-vocab-words? ] [ harvest second prefixed-vocab-words ] }
             [ drop prefixed-words ]