Skip to content

Commit ee22d44

Browse files
committed
acme/Watch: dump first command
1 parent 96bdba9 commit ee22d44

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

acme/Watch/main.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ func main() {
7474
win.Name(pwdSlash + "+watch")
7575
win.Ctl("clean")
7676
win.Ctl("dumpdir " + pwd)
77-
cmd := "dump Watch"
78-
if *recursive {
79-
cmd += " -r"
80-
}
81-
win.Ctl(cmd)
8277
win.Fprintf("tag", "Get Kill Quit ")
8378
win.Fprintf("body", "%% %s\n", strings.Join(args, " "))
8479

@@ -178,11 +173,14 @@ func runSetup(id int) {
178173
// Running synchronously in runner, so no need to watch run.id.
179174
data, _ := win.ReadAll("body")
180175
matches := cmdRE.FindAllIndex(data, -1)
176+
var dumpcmd string
181177
if len(matches) == 0 {
182178
// reset window
183179
win.Addr(",")
184180
win.Write("data", nil)
185181
win.Write("body", []byte(fmt.Sprintf("%% %s\n", strings.Join(args, " "))))
182+
183+
dumpcmd = strings.Join(args, " ")
186184
} else {
187185
end, endByte := utf8.RuneCount(data), len(data)
188186
for i := len(matches) - 1; i >= 0; i-- {
@@ -197,13 +195,25 @@ func runSetup(id int) {
197195
win.Write("data", nil)
198196
}
199197
end, endByte = mStart, m[0]
198+
199+
// Remember first command only
200+
if i == 0 {
201+
dumpcmd = strings.TrimSpace(string(data[m[0]+1 : m[1]])) // skip %
202+
}
200203
}
201204
if end > 0 {
202205
win.Addr(",#%d", end)
203206
win.Write("data", nil)
204207
}
205208
}
206209
win.Addr("#0")
210+
211+
prefix := "dump Watch"
212+
if *recursive {
213+
prefix += " -r"
214+
}
215+
cmd := fmt.Sprintf("%s %s", prefix, dumpcmd)
216+
win.Ctl(cmd)
207217
}
208218

209219
func runBackground(id int, dir string) {

0 commit comments

Comments
 (0)