newedit/utils -> newedit/editutil.

This commit is contained in:
Qi Xiao 2018-10-13 18:38:14 +01:00
parent 31a88b7ba4
commit ea43382430
12 changed files with 20 additions and 20 deletions

View File

@ -10,8 +10,8 @@ import (
"github.com/elves/elvish/edit/ui"
"github.com/elves/elvish/eval"
"github.com/elves/elvish/eval/vals"
"github.com/elves/elvish/newedit/editutil"
"github.com/elves/elvish/newedit/types"
"github.com/elves/elvish/newedit/utils"
)
// TODO(xiaq): Move the implementation into this package.
@ -51,7 +51,7 @@ func callBinding(nt notifier, ev *eval.Evaler, f eval.Callable) types.HandlerAct
err := frame.Call(f, nil, eval.NoOpts)
if err != nil {
if action, ok := eval.Cause(err).(utils.ActionError); ok {
if action, ok := eval.Cause(err).(editutil.ActionError); ok {
return types.HandlerAction(action)
}
// TODO(xiaq): Make the stack trace available.

View File

@ -7,8 +7,8 @@ import (
"github.com/elves/elvish/edit/ui"
"github.com/elves/elvish/eval"
"github.com/elves/elvish/newedit/editutil"
"github.com/elves/elvish/newedit/types"
"github.com/elves/elvish/newedit/utils"
)
func TestKeyHandlerFromBinding_CallsBinding(t *testing.T) {
@ -88,7 +88,7 @@ func TestCallBinding_CapturesAction(t *testing.T) {
nt := &fakeNotifier{}
action := callBinding(nt, ev, eval.NewBuiltinFn("test", func() error {
return utils.ActionError(types.CommitCode)
return editutil.ActionError(types.CommitCode)
}))
if action != types.CommitCode {
t.Errorf("got ret = %v, want %v", action, types.CommitCode)

View File

@ -2,8 +2,8 @@ package newedit
import (
"github.com/elves/elvish/edit/eddefs"
"github.com/elves/elvish/newedit/editutil"
"github.com/elves/elvish/newedit/types"
"github.com/elves/elvish/newedit/utils"
)
//elvish:doc-fn binding-map
@ -18,7 +18,7 @@ var makeBindingMap = eddefs.MakeBindingMap
// special exception.
func exitBinding() error {
return utils.ActionError(types.NoAction)
return editutil.ActionError(types.NoAction)
}
//elvish:doc-fn commit-code
@ -27,5 +27,5 @@ func exitBinding() error {
// being edited. Internally, this works by raising a special exception.
func commitCode() error {
return utils.ActionError(types.CommitCode)
return editutil.ActionError(types.CommitCode)
}

View File

@ -1,8 +1,8 @@
package core
import (
"github.com/elves/elvish/newedit/editutil"
"github.com/elves/elvish/newedit/types"
"github.com/elves/elvish/newedit/utils"
)
// Returns the first non-nil value. If all are nil, return utils.BasicMode{}
@ -12,5 +12,5 @@ func getMode(modes ...types.Mode) types.Mode {
return mode
}
}
return utils.BasicMode{}
return editutil.BasicMode{}
}

View File

@ -1,4 +1,4 @@
package utils
package editutil
import (
"fmt"

View File

@ -1,4 +1,4 @@
package utils
package editutil
import (
"testing"

View File

@ -1,4 +1,4 @@
package utils
package editutil
import (
"unicode/utf8"

View File

@ -1,4 +1,4 @@
package utils
package editutil
import (
"fmt"

2
newedit/editutil/doc.go Normal file
View File

@ -0,0 +1,2 @@
// Package editutil provides utilities for the editor.
package editutil

View File

@ -9,8 +9,8 @@ import (
"github.com/elves/elvish/edit/tty"
"github.com/elves/elvish/edit/ui"
"github.com/elves/elvish/newedit/editutil"
"github.com/elves/elvish/newedit/types"
"github.com/elves/elvish/newedit/utils"
"github.com/elves/elvish/parse"
)
@ -132,7 +132,7 @@ func (m *Mode) handleKey(k ui.Key, st *types.State) types.HandlerAction {
if m.KeyHandler != nil {
action = m.KeyHandler(k)
} else {
action = utils.BasicHandler(tty.KeyEvent(k), st)
action = editutil.BasicHandler(tty.KeyEvent(k), st)
}
if k.Mod != 0 || k.Rune < 0 {
m.inserts = ""

View File

@ -5,9 +5,9 @@ import (
"github.com/elves/elvish/eval"
"github.com/elves/elvish/eval/vals"
"github.com/elves/elvish/eval/vars"
"github.com/elves/elvish/newedit/editutil"
"github.com/elves/elvish/newedit/insert"
"github.com/elves/elvish/newedit/types"
"github.com/elves/elvish/newedit/utils"
"github.com/xiaq/persistent/hashmap"
)
@ -32,9 +32,9 @@ func initInsert(ed editor, ev *eval.Evaler) (*insert.Mode, eval.Ns) {
}.AddBuiltinFns("<edit:insert>:", map[string]interface{}{
"start": func() { st.SetMode(m) },
"default-handler": func() error {
action := utils.BasicHandler(tty.KeyEvent(st.BindingKey()), st)
action := editutil.BasicHandler(tty.KeyEvent(st.BindingKey()), st)
if action != types.NoAction {
return utils.ActionError(action)
return editutil.ActionError(action)
}
return nil
},

View File

@ -1,2 +0,0 @@
// Package utils provides utilities for the editor.
package utils