github.com/ladydascalie/elvish@v0.0.0-20170703214355-2964dd3ece7f/edit/abbr.go (about)

     1  package edit
     2  
     3  import "github.com/elves/elvish/eval"
     4  
     5  var _ = registerVariable("abbr", func() eval.Variable {
     6  	return eval.NewPtrVariableWithValidator(
     7  		eval.NewMap(make(map[eval.Value]eval.Value)), eval.ShouldBeMap)
     8  })
     9  
    10  func (ed *Editor) abbr() eval.Map {
    11  	return ed.variables["abbr"].Get().(eval.Map)
    12  }
    13  
    14  func (ed *Editor) abbrIterate(cb func(abbr, full string) bool) {
    15  	m := ed.abbr()
    16  	m.IterateKey(func(k eval.Value) bool {
    17  		abbr, ok := k.(eval.String)
    18  		if !ok {
    19  			return true
    20  		}
    21  		full, ok := m.IndexOne(k).(eval.String)
    22  		if !ok {
    23  			return true
    24  		}
    25  		return cb(string(abbr), string(full))
    26  	})
    27  }