From bfb74e76ef7dfe305a26010edc86dac456034c3e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 9 Nov 2026 02:14:21 -0300 Subject: locality: single-caller helpers beside their caller: File's placeOf and restoreName beside undoStep, Query's row makers (clearPlaces, makeAllRows, makeNameRows, feedGrepPlaces) beside produce, look's helpers beside lookAt, lookSpanIn and lookUnresolved, mouse's beside handleMouse and dragUpdate, normal's beside handleNormal and executeNormalAction, and the rest in Core, draw, exec, layout, main, modal, replica, syntax, terminal; Messages.printRight into draw.zig beside joinNotice and edit.spanHas into exec.zig beside operandAt, their only callers Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/File.zig | 92 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'src/File.zig') diff --git a/src/File.zig b/src/File.zig index fc50051c..82661c6d 100644 --- a/src/File.zig +++ b/src/File.zig @@ -27,20 +27,6 @@ const Text = panes.Text; const SYNTAX_CONTEXT_AFTER_ROWS: usize = 2; const long_paint: usize = 16 << 10; -/// Where the pane is in its text and what the text is saved as now: an -/// undo step's edge (Text.Place), kept once, never a copy of the text. -fn placeOf(pane: *const Pane, f: *const State) Text.Place { - return .{ - .cur_row = pane.body.cur_row, - .cur_col = pane.body.cur_col, - .vsel = pane.body.vsel, - .gen = f.history.gen, - .clean = f.revision == f.saved_revision, - .saved_hash = f.saved_hash, - .saved_len = f.saved_len, - }; -} - /// A rename (ninep/pane.zig nameBuffer): the name it ends, kept for an undo /// back across it; `old` is the History's from here (owned), freed if it /// cannot be kept. @@ -49,38 +35,6 @@ pub fn noteRenamed(gpa: std.mem.Allocator, history: *History, old: []u8) void { history.gen +%= 1; } -/// After a step's text went in: if it was under another name, that name -/// back, and the step's saved state with it (Get file, Edit's e), as acme's -/// undo puts them back with the text. -fn restoreName(p: *Pardes, pane: *Pane, f: *State, snap: Text.Place) void { - const history = f.history; - if (snap.gen == history.gen) return; - // The latest name kept for that generation. - var at = history.names.items.len; - const path = while (at > 0) { - at -= 1; - if (history.names.items[at].gen == snap.gen) break history.names.items[at].path; - } else return; - if (std.mem.eql(u8, path, f.path)) { - history.gen = snap.gen; - return; - } - const id = for (p.panes, 0..) |slot, i| { - if (slot == pane) break i; - } else return; - // nameBuffer frees nothing of `path`: it keeps the name it ends. - const back = p.gpa.dupe(u8, path) catch |err| return p.reportError(id, "undo", err); - defer p.gpa.free(back); - pardes.ctlfs.pane.nameBuffer(p, id, back, false) catch |err| return p.reportError(id, "undo", err); - history.gen = snap.gen; - f.saved_hash = snap.saved_hash; - f.saved_len = snap.saved_len; - f.saved_revision = if (snap.clean) f.revision else f.revision -% 1; - f.disk_newer = null; - f.disk_newer_warned = false; - if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); -} - /// A file's undo, which its twins (Zerox) share: its edits as a journal /// (Text.Journal), and the names it had. pub const History = struct { @@ -1231,6 +1185,52 @@ pub fn looksLikeDiff(head: []const u8) bool { return diff.looksLikeDiff(lines[0..n]); } +/// Where the pane is in its text and what the text is saved as now: an +/// undo step's edge (Text.Place), kept once, never a copy of the text. +fn placeOf(pane: *const Pane, f: *const State) Text.Place { + return .{ + .cur_row = pane.body.cur_row, + .cur_col = pane.body.cur_col, + .vsel = pane.body.vsel, + .gen = f.history.gen, + .clean = f.revision == f.saved_revision, + .saved_hash = f.saved_hash, + .saved_len = f.saved_len, + }; +} + +/// After a step's text went in: if it was under another name, that name +/// back, and the step's saved state with it (Get file, Edit's e), as acme's +/// undo puts them back with the text. +fn restoreName(p: *Pardes, pane: *Pane, f: *State, snap: Text.Place) void { + const history = f.history; + if (snap.gen == history.gen) return; + // The latest name kept for that generation. + var at = history.names.items.len; + const path = while (at > 0) { + at -= 1; + if (history.names.items[at].gen == snap.gen) break history.names.items[at].path; + } else return; + if (std.mem.eql(u8, path, f.path)) { + history.gen = snap.gen; + return; + } + const id = for (p.panes, 0..) |slot, i| { + if (slot == pane) break i; + } else return; + // nameBuffer frees nothing of `path`: it keeps the name it ends. + const back = p.gpa.dupe(u8, path) catch |err| return p.reportError(id, "undo", err); + defer p.gpa.free(back); + pardes.ctlfs.pane.nameBuffer(p, id, back, false) catch |err| return p.reportError(id, "undo", err); + history.gen = snap.gen; + f.saved_hash = snap.saved_hash; + f.saved_len = snap.saved_len; + f.saved_revision = if (snap.clean) f.revision else f.revision -% 1; + f.disk_newer = null; + f.disk_newer_warned = false; + if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); +} + pub fn restoreSnap(pane: *Pane, f: *State, snap: Text.Place) void { const n = nlines(pane.gpa, f); const row: usize = @min(@as(usize, @intCast(@max(0, snap.cur_row))), n - 1); -- cgit v1.3