summaryrefslogtreecommitdiff
path: root/src/look.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 12:15:23 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commit9b60771ffcd254772b716fafe488b09d9c2d3e0c (patch)
tree917b658065d2aa1b5b59c797249d1fa5d32c0983 /src/look.zig
parent961bea06443e25a92e02be58136065c2a1ea84c1 (diff)
downloadpardes-9b60771ffcd254772b716fafe488b09d9c2d3e0c.tar.gz
pardes-9b60771ffcd254772b716fafe488b09d9c2d3e0c.zip
idioms #16, edits fail by name: the edit operations return edit.Error (memory, or a terminal's rows not read) and try where they caught and returned, so the key, chord or paste that ran one says the failure (`edit: out of memory`, reportError) where it did nothing; look, Core, File and terminal say theirs the same way, and the prints whose buffer provably fits catch unreachable with why
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/look.zig')
-rw-r--r--src/look.zig58
1 files changed, 30 insertions, 28 deletions
diff --git a/src/look.zig b/src/look.zig
index 52674ecf..22aa4882 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -578,7 +578,7 @@ pub fn submitSearch(p: *Pardes, id: usize) void {
// A PDF's `/` and a terminal's: a text's is its query pane (Query.zig).
_ = runSearch(p, id, armed[slash + 1 ..], .top, true) catch |err| return p.reportError(id, "search", err);
var pattern: std.ArrayList(u8) = .empty;
- normal.appendSearchLiteral(&pattern, p.scratch.allocator(), armed[slash + 1 ..]) catch return;
+ normal.appendSearchLiteral(&pattern, p.scratch.allocator(), armed[slash + 1 ..]) catch |err| return p.reportError(id, "search", err);
p.registers.put(p.gpa, '/', pattern.items, 0, 1, true);
p.registers.last_search = '/';
lookFirstHit(p, id);
@@ -635,7 +635,7 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, start: SearchStart,
const loc: []const u8 = if (has_path)
std.fs.path.basename(pane.file.?.path)
else
- std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{pane.serial}) catch return error.PathTooLong;
+ std.fmt.bufPrint(&idbuf, config.pane_addr ++ "{d}", .{pane.serial}) catch unreachable; // `@p` and a u32: 12 bytes
const cl: usize = @intCast(@max(0, pane.body.cur_row));
const cc: usize = @intCast(@max(0, pane.body.cur_col));
for (lines, 0..) |ln, i| {
@@ -1017,7 +1017,7 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, ke
}
fn selectSpan(p: *Pardes, pane: *Pane, at: Spot) void {
- const text = edit.flatSurface(p, &pane.body) catch return;
+ const text = edit.flatSurface(p, &pane.body) catch |err| return p.reportError(p.view().active, "look", err);
// saturating, not `- 1`: `f.zig:0-5` is a legal thing to type and a
// 1-based zero is the same nothing an absent number is
const acol: i32 = @intCast(at.col -| 1);
@@ -1131,7 +1131,7 @@ fn canonicalLookLocation(p: *Pardes, id: usize, text: []const u8) ?[]const u8 {
if (pane.file) |file| return locationText(p, file.path, target.at);
if (pane.addon) |k| if (k.path.len > 0) return locationText(p, k.path, target.at);
var path: [32]u8 = undefined;
- return locationText(p, std.fmt.bufPrint(&path, config.pane_addr ++ "{d}", .{pane.serial}) catch return null, target.at);
+ return locationText(p, std.fmt.bufPrint(&path, config.pane_addr ++ "{d}", .{pane.serial}) catch unreachable, target.at); // 12 bytes
},
}
}
@@ -1169,7 +1169,7 @@ fn lookOpenFailed(p: *Pardes, id: usize, path: []const u8, err: anyerror) void {
if (err == error.FileNotFound or err == error.NotFound or remote_missing)
return missed(p, id, "{s}: no such file", .{missText(path, &cut)});
var said: [miss_path_cap + 16]u8 = undefined;
- p.reportError(id, std.fmt.bufPrint(&said, "look: {s}", .{missText(path, &cut)}) catch "look", err);
+ p.reportError(id, std.fmt.bufPrint(&said, "look: {s}", .{missText(path, &cut)}) catch unreachable, err); // missText fits miss_path_cap
}
fn missedLine(p: *Pardes, id: usize, path: []const u8, line: usize) void {
@@ -1217,15 +1217,17 @@ test "a zero column after a path is found, in every spelling a look takes" {
fn missed(p: *Pardes, id: usize, comptime fmt: []const u8, args: anytype) void {
p.look_missed = true;
var said: [miss_path_cap + 64]u8 = undefined;
- const why = std.fmt.bufPrint(&said, fmt, args) catch "no match";
+ var w = std.Io.Writer.fixed(&said);
+ w.print(fmt, args) catch {}; // a longer miss is said cut at the buffer's end
+ const why = w.buffered();
var msg: [said.len + 8]u8 = undefined;
// Shown on the pane; logged once, as the err below, not a msg too.
p.fs.unlogged = true;
- p.setMessage(id, std.fmt.bufPrint(&msg, "Look: {s}", .{why}) catch "Look: no match");
+ p.setMessage(id, std.fmt.bufPrint(&msg, "Look: {s}", .{why}) catch unreachable); // `why` fits `said`
p.fs.unlogged = false;
const serial = if (p.panes[id]) |pane| pane.serial else 0;
var rec: [said.len + 32]u8 = undefined;
- pardes.ctlfs.events.noteErrCounted(p, std.fmt.bufPrint(&rec, "{d} look: {s}", .{ serial, why }) catch return);
+ pardes.ctlfs.events.noteErrCounted(p, std.fmt.bufPrint(&rec, "{d} look: {s}", .{ serial, why }) catch unreachable); // a u32 and `why`
}
/// After a look at `path:N` focused its pane: a line past the end focuses
@@ -1235,7 +1237,7 @@ fn settleLine(p: *Pardes, id: usize, path: []const u8, at: Spot, before: usize,
const shown = p.panes[p.view().active] orelse return;
const f = if (shown.file) |*file| file else return;
if (at.line > panes.File.nlines(p.gpa, f)) {
- if (opened) |free| p.removePane(free, null) catch {};
+ if (opened) |free| p.removePane(free, null) catch |err| p.reportError(id, "look", err);
if (p.panes[before] != null) p.view().active = before;
return missedLine(p, id, path, at.line);
}
@@ -1297,7 +1299,7 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text:
const dir = Pardes.paneDir(pane);
var said: [4200]u8 = undefined;
const gone = if (filesystem.localPath(dir)) |local| exec.kindOf(local) != .directory else false;
- if (gone) return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}) catch "look: no such directory");
+ if (gone) return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}) catch unreachable); // 4123 bytes at most
// A file not there is a miss, as `x` and `/abs/x` are: said and
// logged, the write answered with nothing.
var cut: [miss_path_cap + "…".len]u8 = undefined;
@@ -1411,7 +1413,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void {
if ((by_serial or path.len == 0) and pane.isTerminal()) return lookTerminalAddress(p, id, target, expr);
// Named as the pane is, the bare `:addr` (path empty) included.
var serial_name: [32]u8 = undefined;
- const subject = if (pane.addon) |k| k.path else if (path.len > 0) path else std.fmt.bufPrint(&serial_name, config.pane_addr ++ "{d}", .{pane.serial}) catch "the pane";
+ const subject = if (pane.addon) |k| k.path else if (path.len > 0) path else std.fmt.bufPrint(&serial_name, config.pane_addr ++ "{d}", .{pane.serial}) catch unreachable; // 12 bytes
var cut: [miss_path_cap + "…".len]u8 = undefined;
return missed(p, id, "{s} is no text to address", .{missText(subject, &cut)});
};
@@ -1428,9 +1430,9 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void {
// was written: `<file>:N has no line N`.
if (std.fmt.parseInt(usize, expr, 10)) |line| {
var placed: [miss_path_cap + "…".len + 24]u8 = undefined;
- const place = std.fmt.bufPrint(&placed, "{s}:{d}", .{ name, line }) catch name;
+ const place = std.fmt.bufPrint(&placed, "{s}:{d}", .{ name, line }) catch unreachable; // missText and a usize
if (!opened_here) return missedLine(p, target, place, line);
- p.removePane(target, null) catch {};
+ p.removePane(target, null) catch |err| p.reportError(id, "look", err);
if (p.panes[id] != null) v.active = id;
return missedLine(p, id, place, line);
} else |_| {}
@@ -1464,13 +1466,13 @@ fn lookKind(p: *Pardes, id: usize, target: usize, expr_raw: []const u8, opened:
return;
}
var serial_name: [32]u8 = undefined;
- const subject = if (slot.path.len > 0) slot.path else std.fmt.bufPrint(&serial_name, config.pane_addr ++ "{d}", .{p.panes[target].?.serial}) catch "the pane";
+ const subject = if (slot.path.len > 0) slot.path else std.fmt.bufPrint(&serial_name, config.pane_addr ++ "{d}", .{p.panes[target].?.serial}) catch unreachable; // 12 bytes
var cut: [miss_path_cap + "…".len]u8 = undefined;
const name = missText(subject, &cut);
if (opened) {
var kept: [miss_path_cap + "…".len]u8 = undefined;
@memcpy(kept[0..name.len], name);
- p.removePane(target, null) catch {};
+ p.removePane(target, null) catch |err| p.reportError(id, "look", err);
if (p.panes[id] != null) p.view().active = id;
return missed(p, id, "{s} {s}", .{ kept[0..name.len], if (said.len > 0) said.slice() else "is no text to address" });
}
@@ -1478,15 +1480,15 @@ fn lookKind(p: *Pardes, id: usize, target: usize, expr_raw: []const u8, opened:
}
/// A place as `address` takes it: `12`, `12:3`.
-fn spotText(at: Spot, buf: *[32]u8) []const u8 {
- if (at.col == 0) return std.fmt.bufPrint(buf, "{d}", .{at.line}) catch "";
- return std.fmt.bufPrint(buf, "{d}:{d}", .{ at.line, at.col }) catch "";
+fn spotText(at: Spot, buf: *[41]u8) []const u8 {
+ if (at.col == 0) return std.fmt.bufPrint(buf, "{d}", .{at.line}) catch unreachable; // two usizes fit 41
+ return std.fmt.bufPrint(buf, "{d}:{d}", .{ at.line, at.col }) catch unreachable;
}
fn closeAndMiss(p: *Pardes, id: usize, opened: usize, name: []const u8, why: []const u8) void {
var kept: [miss_path_cap + "…".len]u8 = undefined;
@memcpy(kept[0..name.len], name);
- p.removePane(opened, null) catch {};
+ p.removePane(opened, null) catch |err| p.reportError(id, "look", err);
if (p.panes[id] != null) p.view().active = id;
missed(p, id, "{s}: {s}", .{ kept[0..name.len], why });
}
@@ -1504,8 +1506,8 @@ fn lookTerminalAddress(p: *Pardes, id: usize, target: usize, expr: []const u8) v
var dot: u32 = 0;
for (lines, 0..) |ln, i| {
if (i == row) dot = @intCast(text.items.len + @min(ln.len, @as(usize, @intCast(@max(0, pane.body.cur_col)))));
- text.appendSlice(arena, ln) catch return;
- text.append(arena, '\n') catch return;
+ text.appendSlice(arena, ln) catch |err| return p.reportError(id, "look", err);
+ text.append(arena, '\n') catch |err| return p.reportError(id, "look", err);
}
var a: Addr = .{ .text = text.items, .lim = null, .expr = expr };
const r = a.address(.{ .q0 = dot, .q1 = dot }) orelse return missed(p, id, "{s}", .{a.err});
@@ -1542,7 +1544,7 @@ pub fn reopenAt(p: *Pardes, from: usize, path: []const u8, at: Spot) void {
// A kind's place is its `address`'s (a PDF's page), quietly.
if (pane.addon) |k| if (std.mem.eql(u8, k.path, path)) {
var said: Kind.Buf(160) = .{};
- var place: [32]u8 = undefined;
+ var place: [41]u8 = undefined;
if (at.line > 0) _ = Kind.address(p, id, spotText(.{ .line = at.line }, &place), &said);
return;
};
@@ -1573,7 +1575,7 @@ pub fn reopenAt(p: *Pardes, from: usize, path: []const u8, at: Spot) void {
if (at.line > n or at.end_line > n) {
var said: [miss_path_cap + 64]u8 = undefined;
var cut: [miss_path_cap + "…".len]u8 = undefined;
- p.setMessage(id, std.fmt.bufPrint(&said, "{s} has {d} lines now: at its last", .{ missText(path, &cut), n }) catch "at its last line");
+ p.setMessage(id, std.fmt.bufPrint(&said, "{s} has {d} lines now: at its last", .{ missText(path, &cut), n }) catch unreachable); // missText and a usize
}
}
@@ -1686,7 +1688,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
break :looked operand;
};
// The operand may borrow selected terminal/PDF text released below.
- const txt = p.scratch.allocator().dupe(u8, looked) catch return;
+ const txt = p.scratch.allocator().dupe(u8, looked) catch |err| return p.reportError(id, "look", err);
// A trailing `:` (`a.txt:2:3:`, as a compiler's message ends) is no
// part of the place, as a click's expansion leaves it off.
const bare = std.mem.trimEnd(u8, std.mem.trim(u8, txt, " \t\r\n"), ":");
@@ -1740,7 +1742,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
const target = p.panes[t.id].?;
// A place in a kind's pane is its `address`'s, a miss its to say.
if (target.addon != null and t.at.line > 0) {
- var place: [32]u8 = undefined;
+ var place: [41]u8 = undefined;
return lookKind(p, id, t.id, spotText(t.at, &place), false);
}
// A directory's pane, looked at again: read again.
@@ -1756,7 +1758,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
// ENOENT, no terminal made in it.
if (filesystem.localPath(dir)) |local| if (exec.kindOf(local) != .directory) {
var said: [4200]u8 = undefined;
- return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}) catch "look: no such directory");
+ return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}) catch unreachable); // 4123 bytes at most
};
// acme's: a pane listing it (Dir.zig).
panes.Dir.look(p, id, dir);
@@ -1804,7 +1806,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
settleLine(p, id, target.path, target.at, before, opened);
},
.kind => |target| {
- var place: [32]u8 = undefined;
+ var place: [41]u8 = undefined;
// A row of a list a kind's pane made (a +PdfSections) is that
// pane's place, never another's of the same file: none once it
// is gone.
@@ -1831,7 +1833,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
p.unplaced.set(free);
var said: [miss_path_cap + 160]u8 = undefined;
var cut: [miss_path_cap + "…".len]u8 = undefined;
- return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: {s}", .{ missText(target.path, &cut), made.addon.?.refused.slice() }) catch "look: refused");
+ return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: {s}", .{ missText(target.path, &cut), made.addon.?.refused.slice() }) catch unreachable); // missText and a Buf(96)
}
exec.placeNew(p, id, id, free, .doc);
if (target.at.line > 0) lookKind(p, id, free, spotText(target.at, &place), true);