Skip to content

Commit

Permalink
acme/Watch: dump first command
Browse files Browse the repository at this point in the history
  • Loading branch information
rakoo committed Jun 13, 2024
1 parent 510f6a0 commit 2ae45de
Showing 1 changed file with 15 additions and 5 deletions.
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

0 comments on commit 2ae45de

Please sign in to comment.