github.com/mem/u-root@v2.0.1-0.20181004165302-9b18b4636a33+incompatible/cmds/elvish/edit/abbr.go (about)

     1  package edit
     2  
     3  import (
     4  	"github.com/u-root/u-root/cmds/elvish/eval"
     5  	"github.com/u-root/u-root/cmds/elvish/eval/vals"
     6  	"github.com/u-root/u-root/cmds/elvish/eval/vars"
     7  	"github.com/xiaq/persistent/hashmap"
     8  )
     9  
    10  func init() {
    11  	atEditorInit(func(ed *editor, ns eval.Ns) {
    12  		ed.abbr = vals.EmptyMap
    13  		ns["abbr"] = vars.FromPtr(&ed.abbr)
    14  	})
    15  }
    16  
    17  func abbrIterate(abbr hashmap.Map, cb func(abbr, full string) bool) {
    18  	for it := abbr.Iterator(); it.HasElem(); it.Next() {
    19  		abbrValue, fullValue := it.Elem()
    20  		abbr, ok := abbrValue.(string)
    21  		if !ok {
    22  			continue
    23  		}
    24  		full, ok := fullValue.(string)
    25  		if !ok {
    26  			continue
    27  		}
    28  		if !cb(abbr, full) {
    29  			break
    30  		}
    31  	}
    32  }