Skip to content

Commit

Permalink
Modify exec.go:/lookup to not use a global
Browse files Browse the repository at this point in the history
Prepare to fix a bug by further refactorings in exec.go: make lookup
parametrizable.
  • Loading branch information
rjkroege committed Jan 14, 2025
1 parent f439931 commit 846e008
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Exectab struct {
// TODO(rjk): This could be more idiomatic: each command implements an
// interface. Flags would then be unnecessary.

var exectab = []Exectab{
var globalexectab = []Exectab{
// { "Abort", doabort, false, true /*unused*/, true /*unused*/, },
{"Cut", cut, true, true, true},
{"Del", del, false, false, true /*unused*/},
Expand Down Expand Up @@ -88,7 +88,8 @@ var exectab = []Exectab{

var wsre = regexp.MustCompile("[ \t\n]+")

func lookup(r string) *Exectab {
// TODO(rjk): Exectab is sorted. Consider using a binary search
func lookup(r string, exectab []Exectab ) *Exectab {
r = wsre.ReplaceAllString(r, " ")
r = strings.TrimLeft(r, " ")
words := strings.SplitN(r, " ", 2)
Expand Down Expand Up @@ -190,7 +191,7 @@ func execute(t *Text, aq0 int, aq1 int, external bool, argt *Text) {

r := make([]rune, q1-q0)
t.file.Read(q0, r)
e := lookup(string(r))
e := lookup(string(r), globalexectab)

// Send commands to external client if the target window's event file is
// in use.
Expand Down

0 comments on commit 846e008

Please sign in to comment.