Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acme/Watch: dump first command #117

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions acme/Watch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ func main() {
win.Name(pwdSlash + "+watch")
win.Ctl("clean")
win.Ctl("dumpdir " + pwd)
cmd := "dump Watch"
if *recursive {
cmd += " -r"
}
win.Ctl(cmd)
win.Fprintf("tag", "Get Kill Quit ")
win.Fprintf("body", "%% %s\n", strings.Join(args, " "))

Expand Down Expand Up @@ -178,11 +173,14 @@ func runSetup(id int) {
// Running synchronously in runner, so no need to watch run.id.
data, _ := win.ReadAll("body")
matches := cmdRE.FindAllIndex(data, -1)
var dumpcmd string
if len(matches) == 0 {
// reset window
win.Addr(",")
win.Write("data", nil)
win.Write("body", []byte(fmt.Sprintf("%% %s\n", strings.Join(args, " "))))

dumpcmd = strings.Join(args, " ")
} else {
end, endByte := utf8.RuneCount(data), len(data)
for i := len(matches) - 1; i >= 0; i-- {
Expand All @@ -197,13 +195,25 @@ func runSetup(id int) {
win.Write("data", nil)
}
end, endByte = mStart, m[0]

// Remember first command only
if i == 0 {
dumpcmd = strings.TrimSpace(string(data[m[0]+1 : m[1]])) // skip %
}
}
if end > 0 {
win.Addr(",#%d", end)
win.Write("data", nil)
}
}
win.Addr("#0")

prefix := "dump Watch"
if *recursive {
prefix += " -r"
}
cmd := fmt.Sprintf("%s %s", prefix, dumpcmd)
win.Ctl(cmd)
}

func runBackground(id int, dir string) {
Expand Down