diff options
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 { |
