diff options
Diffstat (limited to 'core/edit_cmd.zig')
| -rw-r--r-- | core/edit_cmd.zig | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/core/edit_cmd.zig b/core/edit_cmd.zig index 495ec786..43006503 100644 --- a/core/edit_cmd.zig +++ b/core/edit_cmd.zig @@ -151,7 +151,7 @@ fn fileOf(arena: std.mem.Allocator, pane: *panes.Pane, id: usize) !sam.File { pub fn run(p: *Pardes, id: usize, command: []const u8) void { const pane = p.panes[id] orelse return; if (ninep_pane.fileOf(pane) == null) return p.reportFailure(id, "Edit: only a text pane is edited"); - const pd = p.gpa.create(Pending) catch |err| return p.reportError(id, "Edit", err); + const pd = p.gpa.create(Pending) catch |err| return p.reportError(.at(id), "Edit", err); pd.* = .{ .arena = .init(p.gpa), .origin = id, .origin_serial = pane.serial }; var keep = false; defer if (!keep) pd.deinit(p.gpa); @@ -163,7 +163,7 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void { for (p.panes, 0..) |slot, i| { const q = slot orelse continue; if (q.file == null) continue; - files.append(arena, fileOf(arena, q, i) catch |err| return p.reportError(id, "Edit", err)) catch |err| return p.reportError(id, "Edit", err); + files.append(arena, fileOf(arena, q, i) catch |err| return p.reportError(.at(id), "Edit", err)) catch |err| return p.reportError(.at(id), "Edit", err); } std.mem.sort(sam.File, files.items, p, struct { fn before(core: *Pardes, a: sam.File, b: sam.File) bool { @@ -179,7 +179,7 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void { var text: pardes.Kind.Buf(260) = .{}; const res = sam.run(arena, files.items, cur, command, .{ .ctx = &world, .check = World.check, .open = World.open, .read = World.read, .refuseGet = World.refuseGet, .home = p.sessionHome(), .tape = p.tape }, &why) catch |err| switch (err) { error.Edit => return p.reportFailure(id, text.print("Edit: {s}", .{why.text()})), - error.OutOfMemory => return p.reportError(id, "Edit", err), + error.OutOfMemory => return p.reportError(.at(id), "Edit", err), }; // acme's Edit blocks the editor while its commands run; here the editor // goes on, and so does any Edit that runs no command and leaves alone @@ -198,13 +198,13 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void { } } if (res.undo != 0) { - for (0..@abs(res.undo)) |_| panes.File.undoStep(p, pane, res.undo > 0) catch |err| return p.reportError(id, "Edit", err); + for (0..@abs(res.undo)) |_| panes.File.undoStep(p, pane, res.undo > 0) catch |err| return p.reportError(.at(id), "Edit", err); return; } pd.res = res; // What each file was, to know at the end that it still is. - pd.serials = arena.alloc(u32, res.files.len) catch |err| return p.reportError(id, "Edit", err); - pd.revisions = arena.alloc(u32, res.files.len) catch |err| return p.reportError(id, "Edit", err); + pd.serials = arena.alloc(u32, res.files.len) catch |err| return p.reportError(.at(id), "Edit", err); + pd.revisions = arena.alloc(u32, res.files.len) catch |err| return p.reportError(.at(id), "Edit", err); for (res.files, 0..) |f, i| { const q = p.panes[f.id].?; pd.serials[i] = q.serial; @@ -216,14 +216,14 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void { // text may change while they run, and the Edit is then refused), in // its file's directory. const n = res.jobs.len; - const commands = arena.alloc([]const u8, n) catch |err| return p.reportError(id, "Edit", err); - const cwds = arena.alloc([]const u8, n) catch |err| return p.reportError(id, "Edit", err); - const inputs = arena.alloc([]const u8, n) catch |err| return p.reportError(id, "Edit", err); + const commands = arena.alloc([]const u8, n) catch |err| return p.reportError(.at(id), "Edit", err); + const cwds = arena.alloc([]const u8, n) catch |err| return p.reportError(.at(id), "Edit", err); + const inputs = arena.alloc([]const u8, n) catch |err| return p.reportError(.at(id), "Edit", err); for (res.jobs, 0..) |job, i| { const f = res.files[job.file]; commands[i] = job.command; - cwds[i] = arena.dupe(u8, Pardes.paneDir(p.panes[f.id].?)) catch |err| return p.reportError(id, "Edit", err); - inputs[i] = if (job.c == '<') "" else arena.dupe(u8, f.text[job.q0..job.q1]) catch |err| return p.reportError(id, "Edit", err); + cwds[i] = arena.dupe(u8, Pardes.paneDir(p.panes[f.id].?)) catch |err| return p.reportError(.at(id), "Edit", err); + inputs[i] = if (job.c == '<') "" else arena.dupe(u8, f.text[job.q0..job.q1]) catch |err| return p.reportError(.at(id), "Edit", err); } p.pipe.seq +%= 1; pd.id = p.pipe.seq; @@ -234,7 +234,7 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void { .inputs = inputs, .commands = commands, .cwds = cwds, - .shell = arena.dupe(u8, p.shellBin()) catch |err| return p.reportError(id, "Edit", err), + .shell = arena.dupe(u8, p.shellBin()) catch |err| return p.reportError(.at(id), "Edit", err), .token = selection_pipe.newToken(), // What a pane's command is given: $PARDES_MOUNT, $PARDES_9P, // $PARDES_PID, $winid as the Edit's pane. @@ -285,7 +285,7 @@ pub fn cancel(p: *Pardes) void { p.pipe.edit_run = null; selection_pipe.stop(pd.request.token); if (p.panes[pd.origin]) |pane| if (pane.serial == pd.origin_serial) - p.setMessage(pd.origin, "Edit: interrupted; nothing changed"); + p.setMessage(.at(pd.origin), "Edit: interrupted; nothing changed"); pd.deinit(p.gpa); } @@ -376,10 +376,10 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void { } pf.disk_newer = null; }; - const path = p.gpa.dupe(u8, wr.path) catch |err| return p.reportError(at, "Edit", err); + const path = p.gpa.dupe(u8, wr.path) catch |err| return p.reportError(.at(at), "Edit", err); const bytes = p.gpa.dupe(u8, wr.bytes) catch |err| { p.gpa.free(path); - return p.reportError(at, "Edit", err); + return p.reportError(.at(at), "Edit", err); }; const own = std.mem.eql(u8, wr.path, pane.file.?.path); p.pipe.writes.append(p.gpa, .{ @@ -394,7 +394,7 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void { }) catch |err| { p.gpa.free(path); p.gpa.free(bytes); - return p.reportError(at, "Edit", err); + return p.reportError(.at(at), "Edit", err); }; } if (res.writes.len > 0) p.emit(.edit_write); @@ -406,18 +406,18 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void { o.text = outputs[j]; }; if (ops.len > 0) { - const new = sam.apply(p.gpa, pf.content, ops) catch |err| return p.reportError(at, "Edit", err); + const new = sam.apply(p.gpa, pf.content, ops) catch |err| return p.reportError(.at(at), "Edit", err); // `s/a/a/` changes nothing: no undo step, no new revision. if (std.mem.eql(u8, new, pf.content)) p.gpa.free(new) else { panes.File.pushUndo(p, pane) catch |err| { p.gpa.free(new); - return p.reportError(at, "Edit", err); + return p.reportError(.at(at), "Edit", err); }; panes.File.setContent(p, pf, new); } } if (ops.len > 0 or f.moved) ninep_pane.setDot(p.settings.tab, pane, sam.moveDot(f.dot, ops)); - if (f.renamed) ninep_pane.nameBuffer(p, f.id, f.name, false) catch |err| p.reportError(f.id, "Edit", err); + if (f.renamed) ninep_pane.nameBuffer(p, f.id, f.name, false) catch |err| p.reportError(.at(f.id), "Edit", err); } // What was printed, `>`'s output in its place among it. if (res.printed.len > 0 or outputs.len > 0) { @@ -426,11 +426,11 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void { var from: usize = 0; for (res.jobs, 0..) |job, j| { if (job.c != '>') continue; - out.appendSlice(p.gpa, res.printed[from..job.at]) catch |err| return p.reportError(at, "Edit", err); - out.appendSlice(p.gpa, outputs[j]) catch |err| return p.reportError(at, "Edit", err); + out.appendSlice(p.gpa, res.printed[from..job.at]) catch |err| return p.reportError(.at(at), "Edit", err); + out.appendSlice(p.gpa, outputs[j]) catch |err| return p.reportError(.at(at), "Edit", err); from = job.at; } - out.appendSlice(p.gpa, res.printed[from..]) catch |err| return p.reportError(at, "Edit", err); + out.appendSlice(p.gpa, res.printed[from..]) catch |err| return p.reportError(.at(at), "Edit", err); // Printed, the keyboard stays where it was: a +Errors made for it // does not take it, so the next Edit lands where this one did. const was = p.view().active; @@ -447,7 +447,7 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void { if (!f.close) continue; const pane = p.panes[f.id] orelse continue; if (builtins.warnModifiedIn(.{ .p = p, .pane = pane, .id = f.id, .txt = "", .arg = null }, .Del, .{ .pane = f.id })) continue; - p.removePane(f.id, null) catch |err| p.reportError(f.id, "Edit", err); + p.removePane(f.id, null) catch |err| p.reportError(.at(f.id), "Edit", err); } } |
