From 8c74f9a8f199ea0c2d20cc524358d224ea192005 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 1 Oct 2026 17:48:02 -0300 Subject: Get reads a pane's file again, refusing unsaved edits once as Del does, and Get file loads that file into the pane; in a directory pane it reads the directory again. Load is Restore, as Put is Save; Abort's refusal says it is acme's debugging word Co-Authored-By: Claude Opus 5.5 --- src/builtins.zig | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/builtins.zig') diff --git a/src/builtins.zig b/src/builtins.zig index 1172fa78..1d524514 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1116,6 +1116,34 @@ pub const ClipReplace = struct { // ---- panes and columns ---- +/// acme's Get: the pane's file read again, its unsaved edits refused once +/// as Del refuses them. `Get file` loads that file into the pane instead, +/// the pane taking its name. +pub const Get = struct { + pub const takes_arg = true; + pub fn run(c: Ctx) void { + const ctl = @import("ninep/ctl.zig"); + const f = if (c.pane.file) |*file| file else return c.p.reportFailure(c.id, "Get: only a file pane takes it"); + // A directory pane: the directory read again (Dir.zig), as acme's + // Get is in a directory window. + if (f.listing != null) 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"); + if (ctl.getRefused(c.p, c.pane, "Get")) |said| return c.p.reportFailure(c.id, said); + const typed = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); + if (typed.len > 0) { + var home_buf: [4096]u8 = undefined; + const full = std.fs.path.resolvePosix(c.p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), @import("fs.zig").expandHome(typed, &home_buf) }) catch return; + @import("ninep/pane.zig").nameBuffer(c.p, c.id, full, false) catch return c.p.reportFailure(c.id, "Get: invalid file name"); + } + var failed: anyerror = error.Unexpected; + if (ctl.get(c.p, c.pane, &failed) != 0) { + var said: [320]u8 = undefined; + const path = c.pane.file.?.path; + c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Get: {s}: {s}", .{ path[0..@min(path.len, 256)], if (failed == error.FileNotFound) "no such file" else "cannot be read" }) catch "Get: cannot be read"); + } + } +}; + /// Write the pane's text to its file, or to the file its argument names. pub const Save = struct { pub const takes_arg = true; -- cgit v1.3