From b90ae5be38f567a77974ca6ba87d8634e26a8511 Mon Sep 17 00:00:00 2001 From: camsn0w Date: Mon, 10 Jan 2022 18:00:09 -0700 Subject: [PATCH] Changed alltofile to search by regex rather than find an exact match. --- ecmd.go | 17 ++++++++++++----- edit_test.go | 11 +++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ecmd.go b/ecmd.go index 33d12040..9c8e5897 100644 --- a/ecmd.go +++ b/ecmd.go @@ -1065,7 +1065,7 @@ type ToOEB struct { r string } -func alltofile(w *Window, tp *ToOEB) { +func alltofile(w *Window, tp *ToOEB, filenameregex *AcmeRegexp) { if tp.oeb != nil { return } @@ -1078,8 +1078,9 @@ func alltofile(w *Window, tp *ToOEB) { return } // if w.nopen[QWevent] > 0 { - // return; - if tp.r == t.file.Name() { + // return + + if filenameregex.FindString(t.file.Name()) != "" { tp.oeb = t.file } } @@ -1089,9 +1090,15 @@ func toOEB(r string) *file.ObservableEditableBuffer { t.r = strings.TrimLeft(r, " \t\n") t.oeb = nil - global.row.AllWindows(func(w *Window) { alltofile(w, &t) }) + + filenameregex, err := rxcompile(t.r) + if err != nil { + editerror("match not found for\"%v\"", t.r) + } + + global.row.AllWindows(func(w *Window) { alltofile(w, &t, filenameregex) }) if t.oeb == nil { - editerror("no such file\"%v\"", t.r) + editerror("match not found for\"%v\"", t.r) } return t.oeb } diff --git a/edit_test.go b/edit_test.go index e1c80c84..fb31fc6c 100644 --- a/edit_test.go +++ b/edit_test.go @@ -292,6 +292,12 @@ func TestEditMultipleWindows(t *testing.T) { t.Fatalf("can't make a temp file because: %v\n", err) } + fn4, cleaner, err := makeTempFile("file four\n") + defer cleaner() + if err != nil { + t.Fatalf("can't make a temp file because: %v\n", err) + } + testtab := []struct { dot Range filename string @@ -376,6 +382,10 @@ func TestEditMultipleWindows(t *testing.T) { // " + alt_example_2\n'+. alt_example_2\n", // NB: scaffold-built buffer starts as not-dirty " + alt_example_2\n +. alt_example_2\n", // NB: scaffold-built buffer starts as not-dirty }}, + {Range{0, 0}, fn4, "b " + fn4[:len(fn4)-2] + "." + "\ni/Outer Space/", []string{ + "Outer Space" + contents, + alt_contents, + }, []string{"'+. " + fn4 + "\n"}}, // u // 10 @@ -434,6 +444,7 @@ func TestEditMultipleWindows(t *testing.T) { } if got, want := len(warnings), len(test.expectedwarns); got != want { + fmt.Printf("Warnings: %v", warnings[0].buf.String()) t.Errorf("test %d: expected %d warnings but got %d warnings", i, want, got) return }