diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-07 01:02:25 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-07 01:42:27 -0300 |
| commit | 6decf23fe8ac1ce6b48dac42a3502900f6e251b7 (patch) | |
| tree | 5bdad28b45ca43f6494f34057e3211443ec26f50 /src/builtins.zig | |
| parent | f316b46caea6ecf947989114c37af8288b37dbf5 (diff) | |
| download | pardes-6decf23fe8ac1ce6b48dac42a3502900f6e251b7.tar.gz pardes-6decf23fe8ac1ce6b48dac42a3502900f6e251b7.zip | |
follow: `Follow` (SPC c f) is Emacs's follow-mode, one text across a chain of Zerox twins shown in column order as consecutive pages (File.followChain, which syncTwins runs only for a twin group holding a chain): a scroll of any page reflows the others from it, the keyboard's page leaves its inner edges to the cursor, which goes on into the next page rather than scrolling it, the chain's ends scroll it as one pane, `Unfollow` on a follower's tag (or Del) takes a pane out, and the chain is a twin's `follow` flag with each view's `follow_scroll`, so a dump, Restore and replicas carry it; test/behaviour/follow.zig and follow.snap pin it, the reference, guide, changelog and builtins-json say it, and the builtins, leader and ttyhelp goldens list SPC c f
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/builtins.zig')
| -rw-r--r-- | src/builtins.zig | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/builtins.zig b/src/builtins.zig index 15319d6e..c41b3e1b 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1785,6 +1785,57 @@ pub const Right = struct { } }; +/// Emacs's follow-mode: one text across a chain of panes as consecutive +/// pages, each going on where the one before ends, scrolled as one. Adds a +/// page, a Zerox twin, at the end of the column right of the chain's last, +/// or in a new column there; its tag has Unfollow. +pub const Follow = struct { + pub fn run(c: Ctx) void { + if (@import("edit_cmd.zig").busyOn(c.p, c.id)) return c.p.reportFailure(c.id, "Follow: " ++ @import("edit_cmd.zig").e_busy); + const f = if (c.pane.file) |*file| file else return c.p.reportFailure(c.id, "Follow: only a file pane takes it"); + if (f.output != null or f.listing != null or f.mini != null) return c.p.reportFailure(c.id, "Follow: only a file pane takes it"); + // One chain a text: the new page goes after its last, in column order. + const v = c.p.view(); + var last = c.id; + for (v.cols[0..v.ncol]) |col| for (col.panes[0..col.n]) |id| { + const other = if (c.p.panes[id].?.file) |*file| file else continue; + if (f.twin != 0 and other.twin == f.twin and other.follow) last = id; + }; + if (!f.follow and last != c.id) return c.p.reportFailure(c.id, "Follow: this text has a chain: Follow on one of its panes"); + const col = (layout.findPane(c.p, last) orelse return c.p.reportFailure(c.id, "Follow: the pane is not laid out")).col; + const free = c.p.freeSlot() orelse return c.p.reportError(c.id, "Follow", error.NoPaneSlots); + const made = panes.File.zerox(c.p, c.id, free) catch |err| return c.p.reportError(c.id, "Follow", err); + const keep = v.active; + if (col + 1 < v.ncol) { + c.p.exec_column = col + 1; + defer c.p.exec_column = null; + exec.placeNew(c.p, c.id, null, free, .scratch); + if (c.p.unplaced.isSet(free)) return; + } else if (!layout.splitColumn(c.p, last, free, false)) { + c.p.unplaced.set(free); + return c.p.reportFailure(c.id, "Follow: no space for a column: this one is too narrow to split"); + } + // The keyboard stays on the page it was on. + v.active = keep; + if (layout.findPane(c.p, keep)) |at| c.p.setActiveColumn(at.col); + f.follow = true; + made.file.?.follow = true; + c.pane.follow_scroll = f.scroll; + made.follow_scroll = made.file.?.scroll; + made.appendTag(" Unfollow") catch |err| c.p.reportError(c.id, "Follow", err); + } +}; + +/// Take this pane out of its Follow chain: it stays, a Zerox twin with the +/// scroll it has, and the chain closes up behind it. +pub const Unfollow = struct { + pub fn run(c: Ctx) void { + const f = if (c.pane.file) |*file| file else return c.p.reportFailure(c.id, "Unfollow: this pane is in no Follow chain"); + if (!f.follow) return c.p.reportFailure(c.id, "Unfollow: this pane is in no Follow chain"); + panes.File.unchain(c.pane); + } +}; + /// Window mode: h/j/k/l move an outline between the panes; Enter or Esc /// focuses the outlined pane, `:` its tag, the letter shown on a pane that one; d is Del on it (then k or j between two), c Collapse. pub const Window = struct { |
