github.com/markusbkk/elvish@v0.0.0-20231204143114-91dc52438621/pkg/edit/command_api.go (about)

     1  package edit
     2  
     3  // Implementation of the editor "command" mode.
     4  
     5  import (
     6  	"github.com/markusbkk/elvish/pkg/cli/modes"
     7  	"github.com/markusbkk/elvish/pkg/eval"
     8  )
     9  
    10  //elvdoc:var command:binding
    11  //
    12  // Key bindings for command mode. This is currently a very small subset of Vi
    13  // command mode bindings.
    14  //
    15  // @cf edit:command:start
    16  
    17  //elvdoc:fn command:start
    18  //
    19  // Enter command mode. This mode is intended to emulate Vi's command mode, but
    20  // it is very incomplete right now.
    21  //
    22  // @cf edit:command:binding
    23  
    24  func initCommandAPI(ed *Editor, ev *eval.Evaler, nb eval.NsBuilder) {
    25  	bindingVar := newBindingVar(emptyBindingsMap)
    26  	bindings := newMapBindings(ed, ev, bindingVar)
    27  	nb.AddNs("command",
    28  		eval.BuildNsNamed("edit:command").
    29  			AddVar("binding", bindingVar).
    30  			AddGoFns(map[string]interface{}{
    31  				"start": func() {
    32  					w := modes.NewStub(modes.StubSpec{
    33  						Bindings: bindings,
    34  						Name:     " COMMAND ",
    35  					})
    36  					ed.app.PushAddon(w)
    37  				},
    38  			}))
    39  }