summaryrefslogtreecommitdiff
path: root/src/builtins.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-09 03:29:30 -0300
committerGabriel Schneider <[email protected]>2026-11-09 03:30:49 -0300
commit84c8209d02f6830db861c3a8dde0c710c88075f0 (patch)
tree10f77e3ab1becb5a0af4de152bb8d8e0e9ee0f03 /src/builtins.zig
parent446292e15d56c9c248dae5d6fde1be3a83ade82e (diff)
downloadpardes-84c8209d02f6830db861c3a8dde0c710c88075f0.tar.gz
pardes-84c8209d02f6830db861c3a8dde0c710c88075f0.zip
idioms: the edit surface fails by name: the undo history (Journal.mark, Text.remember and step, File's, terminal's and edit's pushUndo and undoStep) returns error{OutOfMemory} instead of dropping an undo point, setEditText, enterInsert and insertTab return edit.Error with try where they reported each failure, Registers.put and setYank return error{OutOfMemory} instead of losing a yank, and their other-file callers decide (try under edit.Error, said on the pane by Undo, Redo, Pipe, Edit, Query, keys, look, completion, Incl and Plumb, ENOMEM or null where a 9P write answers, Ask's false); ctl.get and getFile return GetError (fs.ReadError, now named at fs.zig's surface, and InvalidName) for the *anyerror out-parameter and errno, the 9P get, Get and Edit's e mapping it as before; the OOM undo test pins the error; perf.zig's try relabels its harness hash, the three baselines re-keyed to it (their numbers the base's)
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.zig35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/builtins.zig b/src/builtins.zig
index 2e8397e6..e021dd6b 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -843,7 +843,6 @@ pub const Get = struct {
return panes.Dir.show(c.p, c.id, c.id);
}
if (!panes.Output.fileTraits(f.output).saves) return c.p.reportFailure(c.id, "Get: only a file pane takes it");
- var failed: anyerror = error.Unexpected;
var home_buf: [4096]u8 = undefined;
const path = if (typed.len == 0) c.pane.file.?.path else std.Io.Dir.path.resolvePosix(c.p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), @import("fs.zig").expandHome(typed, &home_buf) }) catch |err| return c.p.reportError(c.id, "Get", err);
// A file that is not there, or a directory, is said before unsaved
@@ -855,13 +854,13 @@ pub const Get = struct {
return c.p.reportFailure(c.id, said.print("Get: {s}: {s}", .{ path[0..@min(path.len, 256)], if (kind == null) "no such file" else "is a directory" }));
};
if (ctl.getRefused(c.p, c.pane, "Get")) |said| return c.p.reportFailure(c.id, said);
- const errno = if (typed.len == 0) ctl.get(c.p, c.pane, &failed) else ctl.getFile(c.p, c.pane, path, &failed);
- if (errno != 0) {
+ const got = if (typed.len == 0) ctl.get(c.p, c.pane) else ctl.getFile(c.p, c.pane, path);
+ got catch |err| {
var said: pardes.Kind.Buf(400) = .{};
var words: [128]u8 = undefined;
- const why = if (failed == error.FileNotFound) "no such file" else pardes.Messages.errorWords(failed, &words);
+ const why = if (err == error.FileNotFound) "no such file" else pardes.Messages.errorWords(err, &words);
c.p.reportFailure(c.id, said.print("Get: {s}: {s}", .{ path[0..@min(path.len, 256)], why }));
- }
+ };
}
};
@@ -923,8 +922,11 @@ pub const Incl = struct {
for (p.incl.items) |dir| {
if (std.mem.eql(u8, dir, full)) break;
} else {
- const copy = p.gpa.dupe(u8, full) catch return;
- p.incl.append(p.gpa, copy) catch return p.gpa.free(copy);
+ const copy = p.gpa.dupe(u8, full) catch |err| return p.reportError(c.id, "Incl", err);
+ p.incl.append(p.gpa, copy) catch |err| {
+ p.gpa.free(copy);
+ return p.reportError(c.id, "Incl", err);
+ };
}
}
if (typed.len > 0) return;
@@ -958,19 +960,20 @@ pub const Plumb = struct {
return p.reportFailure(c.id, std.fmt.bufPrint(&said, "Plumb: {s}", .{why}) catch "Plumb: invalid rule");
// One blank between words, as the list shows it.
var rule: std.ArrayList(u8) = .empty;
+ defer rule.deinit(p.gpa);
var words = std.mem.tokenizeAny(u8, typed, " \t");
while (words.next()) |w| {
- if (rule.items.len > 0) rule.append(p.gpa, ' ') catch return rule.deinit(p.gpa);
- rule.appendSlice(p.gpa, w) catch return rule.deinit(p.gpa);
+ if (rule.items.len > 0) rule.append(p.gpa, ' ') catch |err| return p.reportError(c.id, "Plumb", err);
+ rule.appendSlice(p.gpa, w) catch |err| return p.reportError(c.id, "Plumb", err);
}
- const owned = rule.toOwnedSlice(p.gpa) catch return rule.deinit(p.gpa);
- p.plumb.append(p.gpa, owned) catch return p.gpa.free(owned);
+ p.plumb.ensureUnusedCapacity(p.gpa, 1) catch |err| return p.reportError(c.id, "Plumb", err);
+ p.plumb.appendAssumeCapacity(rule.toOwnedSlice(p.gpa) catch |err| return p.reportError(c.id, "Plumb", err));
return;
}
var list: std.Io.Writer.Allocating = .init(p.scratch.allocator());
- list.writer.writeAll("Plumb:") catch return;
- for (p.plumb.items, 0..) |rule, i| list.writer.print("{s} {s}", .{ if (i == 0) "" else ";", rule }) catch return;
- if (p.plumb.items.len == 0) list.writer.writeAll(" none") catch return;
+ list.writer.writeAll("Plumb:") catch |err| return p.reportError(c.id, "Plumb", err);
+ for (p.plumb.items, 0..) |rule, i| list.writer.print("{s} {s}", .{ if (i == 0) "" else ";", rule }) catch |err| return p.reportError(c.id, "Plumb", err);
+ if (p.plumb.items.len == 0) list.writer.writeAll(" none") catch |err| return p.reportError(c.id, "Plumb", err);
p.setMessage(c.id, list.written());
}
};
@@ -1137,7 +1140,7 @@ pub const Undo = struct {
pub fn run(c: Ctx) void {
if (@import("edit_cmd.zig").busyOn(c.p, c.id)) return c.p.reportFailure(c.id, "Undo: " ++ @import("edit_cmd.zig").e_busy);
if (c.pane.file) |f| if (f.history.journal.done == 0) return c.p.setMessage(c.id, "Undo: nothing to undo");
- edit.undoStep(c.p, &c.pane.body, true);
+ edit.undoStep(c.p, &c.pane.body, true) catch |err| c.p.reportError(c.id, "Undo", err);
}
};
@@ -1146,7 +1149,7 @@ pub const Redo = struct {
pub fn run(c: Ctx) void {
if (@import("edit_cmd.zig").busyOn(c.p, c.id)) return c.p.reportFailure(c.id, "Redo: " ++ @import("edit_cmd.zig").e_busy);
if (c.pane.file) |f| if (f.history.journal.done == f.history.journal.steps.items.len) return c.p.setMessage(c.id, "Redo: nothing to redo");
- edit.undoStep(c.p, &c.pane.body, false);
+ edit.undoStep(c.p, &c.pane.body, false) catch |err| c.p.reportError(c.id, "Redo", err);
}
};