diff --git a/pkg/edit/listing.go b/pkg/edit/listing.go index 17ba216f..34d6724b 100644 --- a/pkg/edit/listing.go +++ b/pkg/edit/listing.go @@ -118,7 +118,7 @@ func initLocation(ed *Editor, ev *eval.Evaler, st storedefs.Store, commonBinding }) startMode(ed.app, w, err) })) - ev.AddAfterChdir(func(string) { + ev.AfterChdir = append(ev.AfterChdir, func(string) { wd, err := os.Getwd() if err != nil { // TODO(xiaq): Surface the error. diff --git a/pkg/eval/chdir_test.go b/pkg/eval/chdir_test.go index 85ec01cf..3a2739d1 100644 --- a/pkg/eval/chdir_test.go +++ b/pkg/eval/chdir_test.go @@ -18,8 +18,8 @@ func TestChdir(t *testing.T) { ev := NewEvaler() argDirInBefore, argDirInAfter := "", "" - ev.AddBeforeChdir(func(dir string) { argDirInBefore = dir }) - ev.AddAfterChdir(func(dir string) { argDirInAfter = dir }) + ev.BeforeChdir = append(ev.BeforeChdir, func(dir string) { argDirInBefore = dir }) + ev.AfterChdir = append(ev.AfterChdir, func(dir string) { argDirInAfter = dir }) back := saveWd() defer back() diff --git a/pkg/eval/eval.go b/pkg/eval/eval.go index 01426dbe..fd585c6c 100644 --- a/pkg/eval/eval.go +++ b/pkg/eval/eval.go @@ -280,32 +280,6 @@ func (ev *Evaler) addNumBgJobs(delta int) { ev.numBgJobs += delta } -// SetArgs sets the value of the $args variable to a list of strings, built from -// the given slice. This method must be called before the Evaler is used to -// evaluate any code. -func (ev *Evaler) SetArgs(args []string) { - ev.Args = vals.MakeListSlice(args) -} - -// AddBeforeChdir adds a function to run before changing directory. This method -// must be called before the Evaler is used to evaluate any code. -func (ev *Evaler) AddBeforeChdir(f func(string)) { - ev.BeforeChdir = append(ev.BeforeChdir, f) -} - -// AddAfterChdir adds a function to run after changing directory. This method -// must be called before the Evaler is used to evaluate any code. -func (ev *Evaler) AddAfterChdir(f func(string)) { - ev.AfterChdir = append(ev.AfterChdir, f) -} - -// AddBeforeExit adds a function to run before the Elvish process exits or gets -// replaced (via "exec" on UNIX). This method must be called before the Evaler -// is used to evaluate any code. -func (ev *Evaler) AddBeforeExit(f func()) { - ev.BeforeExit = append(ev.BeforeExit, f) -} - // Chdir changes the current directory, and updates $E:PWD on success // // It runs the functions in beforeChdir immediately before changing the diff --git a/pkg/eval/eval_test.go b/pkg/eval/eval_test.go index 9f821418..179443e9 100644 --- a/pkg/eval/eval_test.go +++ b/pkg/eval/eval_test.go @@ -34,7 +34,7 @@ func TestArgs(t *testing.T) { Test(t, That("put $args").Puts(vals.EmptyList)) TestWithSetup(t, - func(ev *Evaler) { ev.SetArgs([]string{"foo", "bar"}) }, + func(ev *Evaler) { ev.Args = vals.MakeList("foo", "bar") }, That("put $args").Puts(vals.MakeList("foo", "bar"))) } diff --git a/pkg/shell/interact.go b/pkg/shell/interact.go index 442fe4e8..45cbafea 100644 --- a/pkg/shell/interact.go +++ b/pkg/shell/interact.go @@ -67,7 +67,7 @@ func interact(ev *eval.Evaler, fds [3]*os.File, cfg *interactCfg) { daemonClient = cl // Even if error is not nil, we install daemon-related functionalities // anyway. Daemon may eventually come online and become functional. - ev.AddBeforeExit(func() { cl.Close() }) + ev.BeforeExit = append(ev.BeforeExit, func() { cl.Close() }) ev.AddModule("store", store.Ns(cl)) ev.AddModule("daemon", daemon.Ns(cl)) } diff --git a/pkg/shell/script.go b/pkg/shell/script.go index 55428d00..b5789dfb 100644 --- a/pkg/shell/script.go +++ b/pkg/shell/script.go @@ -10,6 +10,7 @@ import ( "src.elv.sh/pkg/diag" "src.elv.sh/pkg/eval" + "src.elv.sh/pkg/eval/vals" "src.elv.sh/pkg/parse" ) @@ -23,7 +24,7 @@ type scriptCfg struct { // Executes a shell script. func script(ev *eval.Evaler, fds [3]*os.File, args []string, cfg *scriptCfg) int { arg0 := args[0] - ev.SetArgs(args[1:]) + ev.Args = vals.MakeListSlice(args[1:]) var name, code string if cfg.Cmd {