Merge pull request #32 from guanqun/add-api-for-set-completion

add a new API to set auto complete
This commit is contained in:
Chzyer 2016-02-23 13:52:35 +08:00
commit a0bb3f70e4
2 changed files with 11 additions and 0 deletions

View File

@ -405,6 +405,10 @@ func (op *Operation) SetConfig(cfg *Config) (*Config, error) {
// so if we use it next time, we need to reopen it by `InitHistory()`
op.history.Init()
if op.cfg.AutoComplete != nil {
op.opCompleter = newOpCompleter(op.buf.w, op)
}
op.opSearch = cfg.opSearch
return old, nil
}

7
std.go
View File

@ -33,6 +33,13 @@ func SetHistoryPath(fp string) {
ins.SetConfig(cfg)
}
func SetAutoComplete(completer AutoCompleter) {
ins := getInstance()
cfg := ins.Config.Clone()
cfg.AutoComplete = completer
ins.SetConfig(cfg)
}
func AddHistory(content string) error {
ins := getInstance()
return ins.SaveHistory(content)