summaryrefslogtreecommitdiff
path: root/src/layout.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout.zig')
-rw-r--r--src/layout.zig20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/layout.zig b/src/layout.zig
index 28f3d270..4aebcf28 100644
--- a/src/layout.zig
+++ b/src/layout.zig
@@ -325,8 +325,14 @@ pub fn removePane(p: *Pardes, id: usize) void {
/// Close column `c` once its panes are gone, its width to the one left of
/// it (the first column's to its right), as acme's rowclose gives it.
pub fn dropColumn(p: *Pardes, c: usize) void {
- std.debug.assert(p.col_n[c] == 0);
const serial = columnSerial(p, c);
+ dropColumnUnannounced(p, c);
+ noteColumn(p, "delcol", serial);
+}
+
+/// dropColumn with no `delcol`, for a column never announced.
+pub fn dropColumnUnannounced(p: *Pardes, c: usize) void {
+ std.debug.assert(p.col_n[c] == 0);
tagline.exitHeader(p);
if (p.ncol > 1) p.col_weight[if (c > 0) c - 1 else c + 1] +|= p.col_weight[c];
p.col_tags[c].deinit(p.gpa);
@@ -341,12 +347,11 @@ pub fn dropColumn(p: *Pardes, c: usize) void {
p.ncol -= 1;
p.col_tags[p.ncol] = .{ .what = .column, .gpa = p.gpa };
p.col_serial[p.ncol] = 0;
- noteColumn(p, "delcol", serial);
}
/// `newcol <serial>` or `delcol <serial>` in the log: the column's serial,
/// as /layout and /col name it.
-fn noteColumn(p: *Pardes, what: []const u8, serial: u32) void {
+pub fn noteColumn(p: *Pardes, what: []const u8, serial: u32) void {
var buf: [16]u8 = undefined;
pardes.ctlfs.events.notePath(p, what, std.fmt.bufPrint(&buf, "{d}", .{serial}) catch return);
}
@@ -649,6 +654,14 @@ pub fn firstColumn(p: *Pardes) ?usize {
}
pub fn insertColumn(p: *Pardes, col: usize, before: bool) ?usize {
+ const c = insertColumnUnannounced(p, col, before) orelse return null;
+ noteColumn(p, "newcol", columnSerial(p, c));
+ return c;
+}
+
+/// insertColumn with no serial given and no `newcol`: a column that may
+/// yet be taken back (Newcol's trial), which then leaves no trace.
+pub fn insertColumnUnannounced(p: *Pardes, col: usize, before: bool) ?usize {
if (!canSplitCol(p, col)) return null;
var old_weight = p.col_weight[col];
if (old_weight < 2 or old_weight % 2 != 0) {
@@ -672,7 +685,6 @@ pub fn insertColumn(p: *Pardes, col: usize, before: bool) ?usize {
p.col_serial[c] = 0;
p.col_n[c] = 0;
p.ncol += 1;
- noteColumn(p, "newcol", columnSerial(p, c));
return c;
}