elvish/edit/abbr.go
2018-02-06 20:44:56 -08:00

32 lines
597 B
Go

package edit
import (
"github.com/elves/elvish/eval"
"github.com/elves/elvish/eval/types"
"github.com/xiaq/persistent/hashmap"
)
func init() {
atEditorInit(func(ed *Editor, ns eval.Ns) {
ed.abbr = types.EmptyMap
ns["abbr"] = eval.NewVariableFromPtr(&ed.abbr)
})
}
func abbrIterate(abbr hashmap.Map, cb func(abbr, full string) bool) {
for it := abbr.Iterator(); it.HasElem(); it.Next() {
abbrValue, fullValue := it.Elem()
abbr, ok := abbrValue.(string)
if !ok {
continue
}
full, ok := fullValue.(string)
if !ok {
continue
}
if !cb(abbr, full) {
break
}
}
}