summaryrefslogtreecommitdiff
path: root/src/builtins.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/builtins.zig')
-rw-r--r--src/builtins.zig35
1 files changed, 7 insertions, 28 deletions
diff --git a/src/builtins.zig b/src/builtins.zig
index da87ba37..ed6ac467 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -555,9 +555,9 @@ fn warnModified(c: Ctx, asking: Pane.Discarding) bool {
/// Which panes a refusal asks about: every one (Exit, Restore), one (Del),
/// or a column's (Delcol).
-const Asked = union(enum) { all, pane: usize, column: usize };
+pub const Asked = union(enum) { all, pane: usize, column: usize };
-fn warnModifiedIn(c: Ctx, asking: Pane.Discarding, which: Asked) bool {
+pub fn warnModifiedIn(c: Ctx, asking: Pane.Discarding, which: Asked) bool {
// Every pane asked about is an `unsaved <serial> <name>` record, as
// acme's rowclean names them all (wind.c:511); the refusal a write
// gets names the one, or counts them, never a list cut short.
@@ -1330,36 +1330,15 @@ pub const Togglettymode = struct {
};
/// acme's Edit (exec.c `edit`, edit.c): sam's command language over the
-/// pane's body, from a tag, a pane ctl or exec. One undo step; a failure
-/// changes nothing and says why. src/sam_edit.zig has what is left out.
+/// open text panes, from a tag, a pane ctl or exec, starting in the pane's
+/// body. One undo step in each file it changes; a failure changes nothing
+/// and says why. src/edit_cmd.zig runs it; src/sam_edit.zig has what is
+/// left out.
pub const Edit = struct {
pub const takes_arg = true;
pub const requires_arg = true;
pub fn run(c: Ctx) void {
- const sam = @import("sam_edit.zig");
- const ninep_pane = @import("ninep/pane.zig");
- const f = ninep_pane.fileOf(c.pane) orelse return c.p.reportFailure(c.id, "Edit: only a text pane is edited");
- const arena = c.p.scratch.allocator();
- var why: sam.Why = .{};
- var said: [260]u8 = undefined;
- const res = sam.run(arena, f.content, ninep_pane.dotOf(c.pane), f.path, c.arg orelse "", &why) catch |err| switch (err) {
- error.Edit => return c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Edit: {s}", .{why.text()}) catch "Edit: failed"),
- error.OutOfMemory => return c.p.reportError(c.id, "Edit", err),
- };
- if (res.undo != 0) {
- for (0..@abs(res.undo)) |_| if (res.undo > 0) panes.File.undo(c.p, c.pane) else panes.File.redo(c.p, c.pane);
- return;
- }
- if (res.ops.len > 0) {
- const new = sam.apply(c.p.gpa, f.content, res.ops) catch |err| return c.p.reportError(c.id, "Edit", err);
- // `s/a/a/` changes nothing: no undo step, no new revision.
- if (std.mem.eql(u8, new, f.content)) c.p.gpa.free(new) else {
- panes.File.pushUndo(c.p, c.pane);
- panes.File.setContent(c.p, f, new);
- }
- }
- ninep_pane.setDot(c.pane, sam.moveDot(res.dot, res.ops));
- if (res.printed.len > 0) _ = ninep_pane.appendErrors(c.p, c.id, res.printed);
+ @import("edit_cmd.zig").run(c.p, c.id, c.arg orelse "");
}
};