diff options
Diffstat (limited to 'src/builtins.zig')
| -rw-r--r-- | src/builtins.zig | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/builtins.zig b/src/builtins.zig index e5c7753d..ada02e0c 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1148,6 +1148,45 @@ pub const Incl = struct { } }; +/// The plumber's rules, for the session, one a line as plumb(6) orders a +/// rule: `Plumb suffix .svg to image` makes a look at an existing `.svg` +/// file an image pane. The user's rules are tried in the order given, +/// before the built-in ones, and the first that matches takes the look. +/// Bare, it lists them; `Plumb -` empties the list. +pub const Plumb = struct { + pub const scope: Scope = .session; + pub const takes_arg = true; + pub fn run(c: Ctx) void { + const p = c.p; + const typed = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); + if (std.mem.eql(u8, typed, "-")) { + for (p.plumb.items) |rule| p.gpa.free(rule); + p.plumb.clearRetainingCapacity(); + return p.setMessage(c.id, "Plumb: none"); + } + if (typed.len > 0) { + var said: [320]u8 = undefined; + if (look.plumbRuleError(&p.kinds, typed)) |why| + 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; + 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); + } + const owned = rule.toOwnedSlice(p.gpa) catch return rule.deinit(p.gpa); + p.plumb.append(p.gpa, owned) catch return p.gpa.free(owned); + 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; + p.setMessage(c.id, list.written()); + } +}; + /// acme's Zerox: a second pane on this pane's file, the same text, undo and /// unsaved state, with a scroll and a cursor of its own (File.zerox). pub const Zerox = struct { |
