Skip to content

Commit

Permalink
support autocomplete for sys topics
Browse files Browse the repository at this point in the history
  • Loading branch information
fzipp committed Aug 4, 2023
1 parent ca65196 commit 283ed04
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var (
specialHelp = regexp.MustCompile(`^\s*\)\s*help\s*$`)
specialGet = regexp.MustCompile(`^\s*\)\s*get\s*["']$`)
specialSave = regexp.MustCompile(`^\s*\)\s*save\s*["']$`)
opSys = regexp.MustCompile(`(|.*\s+)sys(|\s*["'])$`)
)

type defsProvider interface {
Expand All @@ -45,6 +46,14 @@ func makeCompleter(def defsProvider) liner.WordCompleter {
} else if specialGet.MatchString(beforeWord) || specialSave.MatchString(beforeWord) {
words = fileNames()
suffix = ""
} else if opSys.MatchString(beforeWord) {
last := beforeWord[len(beforeWord)-1]
if last == '"' || last == '\'' {
words = sysTopics
} else {
words = []string{"\""}
}
suffix = ""
} else {
ops, err := def.Ops()
if err == nil {
Expand Down
18 changes: 18 additions & 0 deletions words.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,21 @@ var helpTopics = []string{
"types",
"unary",
}

var sysTopics = []string{
"help",
"base",
"cpu",
"date",
"format",
"ibase",
"maxbits",
"maxdigits",
"maxstack",
"now",
"obase",
"origin",
"prompt",
"sec",
"time",
}

0 comments on commit 283ed04

Please sign in to comment.