Skip to content

Commit

Permalink
tools.completion: adding EDITOR: tab completion
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Apr 5, 2023
1 parent a937766 commit a6a311a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
9 changes: 7 additions & 2 deletions basis/tools/completion/completion.factor
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 ;

Expand Down Expand Up @@ -176,6 +179,8 @@ PRIVATE>

: complete-color? ( tokens -- ? ) "COLOR:" complete-token? ;

: complete-editor? ( tokens -- ? ) "EDITOR:" complete-token? ;

<PRIVATE

: complete-string? ( tokens token -- ? )
Expand Down
8 changes: 6 additions & 2 deletions basis/ui/tools/listener/completion/completion.factor
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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 ] ;
Expand All @@ -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" ;
Expand Down Expand Up @@ -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> ]
Expand Down
10 changes: 7 additions & 3 deletions extra/readline-listener/readline-listener.factor
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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 ;

Expand All @@ -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 ]
Expand Down

0 comments on commit a6a311a

Please sign in to comment.