From c4ab29bce30f427decf3e199eebecfd415714a96 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 28 Sep 2026 18:39:01 -0300 Subject: Edit runs sam's command language on a pane's body, as acme's Edit does, in one undo step Over 9P a rename everywhere was a loop of addr and data writes. Edit, from a tag, a pane ctl or exec, parses sam's commands as acme's edit.c does and runs them as ecmd.c does against the text as it was, collecting the changes in order as elog.c logs them and applying them at once: addresses (the addr file's, line:col included), x y g v c a i d s p = m t, u alone, and { }. One undo step; any error, in acme's words, changes nothing, fails a ctl write and is logged. p and = print to the directory's +Errors. Left out, and said: the file commands, the pipes, \1-\9 (mvzr keeps no submatches), and changes out of sequence, which acme applies with a warning. Co-Authored-By: Claude Opus 5.5 --- src/ninep/ctl.zig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/ninep/ctl.zig') diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index d7d50cc6..18068ab1 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -770,6 +770,23 @@ test "a second lock is refused until the holder unlocks or closes, and binds nob for (p.fs.opens) |o| try testing.expect(o.node == 0); } +test "Edit through a pane's ctl renames every foo in one undo step, and a failed one changes nothing" { + const p = try withFile(testing.allocator, "foo x foo y foo\n"); + defer p.deinit(); + const serial = serialOf(p); + const ctl_node = Node.of(serial, .ctl); + const body = Node.of(serial, .body); + try testing.expectEqual(Status.ok, wr(p, ctl_node, "Edit ,x/foo/c/foobar/\n").reply.status); + try testing.expectEqualStrings("foobar x foobar y foobar\n", rd(p, body, 0, 64).bytes); + const failed = wr(p, ctl_node, "Edit ,s/nothing/x/\n"); + try testing.expectEqual(E.IO, failed.errno()); + try testing.expectStringStartsWith(failed.reply.ename, "Edit: no substitution"); + try testing.expectEqualStrings("foobar x foobar y foobar\n", rd(p, body, 0, 64).bytes); + // The whole rename is one undo step. + try testing.expectEqual(Status.ok, wr(p, ctl_node, "Undo").reply.status); + try testing.expectEqualStrings("foo x foo y foo\n", rd(p, body, 0, 64).bytes); +} + test "dirty goes back to 0 when the text is the saved text again" { const p = try withFile(testing.allocator, "one\n"); defer p.deinit(); -- cgit v1.3