mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-15 03:37:52 +08:00
edit: Make argCompleter a field of Editor.
This commit is contained in:
parent
e36b0d8371
commit
b6d57a8be2
|
@ -67,7 +67,8 @@ func installModules(modules map[string]eval.Namespace, ed *Editor) {
|
|||
}
|
||||
ns["binding"] = eval.NewRoVariable(binding)
|
||||
|
||||
ns["completer"] = argCompleter
|
||||
ns["completer"] = ed.argCompleter
|
||||
|
||||
ns[eval.FnPrefix+"complete-getopt"] = eval.NewRoVariable(
|
||||
&eval.BuiltinFn{"le:&complete-getopt", complGetopt})
|
||||
for _, bac := range argCompletersData {
|
||||
|
|
|
@ -17,20 +17,20 @@ var (
|
|||
"": {"complete-filename", complFilename},
|
||||
"sudo": {"complete-sudo", complSudo},
|
||||
}
|
||||
argCompleter eval.Variable
|
||||
)
|
||||
|
||||
func init() {
|
||||
func makeCompleterMap() eval.Map {
|
||||
m := map[eval.Value]eval.Value{}
|
||||
for k, v := range argCompletersData {
|
||||
m[eval.String(k)] = v
|
||||
}
|
||||
argCompleter = eval.NewPtrVariableWithValidator(eval.NewMap(m), eval.ShouldBeMap)
|
||||
return eval.NewMap(m)
|
||||
}
|
||||
|
||||
func completeArg(words []string, ev *eval.Evaler) ([]*candidate, error) {
|
||||
logger.Printf("completing argument: %q", words)
|
||||
m := argCompleter.Get().(eval.Map)
|
||||
// XXX(xiaq): not the best way to get argCompleter.
|
||||
m := ev.Editor.(*Editor).argCompleter.Get().(eval.Map)
|
||||
var v eval.Value
|
||||
if m.HasKey(eval.String(words[0])) {
|
||||
v = m.IndexOne(eval.String(words[0]))
|
||||
|
|
|
@ -47,6 +47,8 @@ type Editor struct {
|
|||
beforeReadLine eval.Variable
|
||||
afterReadLine eval.Variable
|
||||
|
||||
argCompleter eval.Variable
|
||||
|
||||
historyMutex sync.RWMutex
|
||||
|
||||
active bool
|
||||
|
@ -126,6 +128,9 @@ func NewEditor(file *os.File, sigs chan os.Signal, ev *eval.Evaler, st *store.St
|
|||
|
||||
beforeReadLine: eval.NewPtrVariableWithValidator(eval.NewList(), eval.ShouldBeList),
|
||||
afterReadLine: eval.NewPtrVariableWithValidator(eval.NewList(), eval.ShouldBeList),
|
||||
|
||||
argCompleter: eval.NewPtrVariableWithValidator(
|
||||
makeCompleterMap(), eval.ShouldBeMap),
|
||||
}
|
||||
ev.Editor = ed
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user