From a0d367b6c54ff29737662fd7cf5a78d4d183cb20 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 23 Oct 2026 10:56:33 -0300 Subject: Audit (core, modal): goto/insert/select tables, edit through sam.Op and sam.apply, Turn.bump and awaitPast, dead helpers out Co-Authored-By: Claude Opus 5.5 --- src/sam_edit.zig | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) (limited to 'src/sam_edit.zig') diff --git a/src/sam_edit.zig b/src/sam_edit.zig index 94b76816..73cd6ecd 100644 --- a/src/sam_edit.zig +++ b/src/sam_edit.zig @@ -187,9 +187,12 @@ pub fn run(arena: std.mem.Allocator, files: []const File, cur: usize, command: [ /// an a, c or i text block, or the `}` of a group. pub const Wait = enum { none, text, group }; -/// As `needsMore`, saying which: while a text block is open only a `.` -/// line can end it, so a caller need not parse the block again for every -/// line of text in it (ninep/ctl.zig, editEnd), which was quadratic. +/// Whether `command` stops inside a `{` group or an `a`, `c` or `i` text +/// block still waiting for its `.` line, and which: a writer of lines (a +/// ctl, exec) hands an Edit the lines after it until it does not. While a +/// text block is open only a `.` line can end it, so a caller need not +/// parse the block again for every line of text in it (ninep/ctl.zig, +/// editEnd), which was quadratic. pub fn waitsFor(arena: std.mem.Allocator, command: []const u8) Wait { var why: Why = .{}; const src = std.fmt.allocPrint(arena, "{s}\n", .{command}) catch return .none; @@ -217,19 +220,6 @@ fn groupOpen(command: []const u8) bool { return depth > 0; } -/// Whether `command` stops inside a `{` group or an `a`, `c` or `i` text -/// block still waiting for its `.` line: a writer of lines (a ctl, exec) -/// hands an Edit the lines after it until it does not. -pub fn needsMore(arena: std.mem.Allocator, command: []const u8) bool { - var why: Why = .{}; - const src = std.fmt.allocPrint(arena, "{s}\n", .{command}) catch return false; - var ps: Parser = .{ .arena = arena, .src = src, .why = &why }; - while (true) { - const c = ps.parse(0) catch return std.mem.eql(u8, why.text(), "unmatched `{'") or ps.open_text; - if (c == null) return ps.open_text; - } -} - /// Whether `command` holds a `<`, `|` or `>`: its write is answered only /// when they have run (ninep/ctl.zig refuses other lines beside it). pub fn runsCommands(arena: std.mem.Allocator, command: []const u8) bool { @@ -1191,13 +1181,13 @@ test "an Edit wants the lines after it until its braces and text blocks close" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const a = arena_state.allocator(); - try std.testing.expect(needsMore(a, ",x/foo/{")); - try std.testing.expect(needsMore(a, ",x/foo/{\ni/[/")); - try std.testing.expect(!needsMore(a, ",x/foo/{\ni/[/\n}")); - try std.testing.expect(needsMore(a, "$a\nline one")); - try std.testing.expect(!needsMore(a, "$a\nline one\n.")); - try std.testing.expect(!needsMore(a, ",s/{/x/")); - try std.testing.expect(!needsMore(a, ",x/foo/c/bar/")); + try std.testing.expect(waitsFor(a, ",x/foo/{") != .none); + try std.testing.expect(waitsFor(a, ",x/foo/{\ni/[/") != .none); + try std.testing.expectEqual(Wait.none, waitsFor(a, ",x/foo/{\ni/[/\n}")); + try std.testing.expect(waitsFor(a, "$a\nline one") != .none); + try std.testing.expectEqual(Wait.none, waitsFor(a, "$a\nline one\n.")); + try std.testing.expectEqual(Wait.none, waitsFor(a, ",s/{/x/")); + try std.testing.expectEqual(Wait.none, waitsFor(a, ",x/foo/c/bar/")); } test "the dot an Edit leaves selects what a change put where it stood" { -- cgit v1.3