diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-28 19:59:47 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:15 -0300 |
| commit | 1f8de151e382755c1ce597f166ea4552e7f7e8d1 (patch) | |
| tree | 1ed05b6c528dd9db099a249504fdc3b4083fb72f /src/look.zig | |
| parent | 16fe974c7426925f1b7ffc516f149cc1f4ffa390 (diff) | |
| download | pardes-1f8de151e382755c1ce597f166ea4552e7f7e8d1.tar.gz pardes-1f8de151e382755c1ce597f166ea4552e7f7e8d1.zip | |
A look with a blank in its pattern addresses, file:N selects the line, and a miss is said, logged and reads back empty
Round 6: look calc.py:/return a/ was a word search, since a blank ended the address; calc.py:99 past the end focused the file and said nothing; and /look still read back the pane before a miss. A pattern after the colon may now hold blanks; file:N selects the line, newline included, as acme's does; a line past the end opens and focuses nothing; and every miss (no match, a bad address, a line past the end) says so, logs err <serial> look: why, keeps the selection, and leaves look reading back empty. Documented, with file:0/re/ for the first match, since acme evaluates the address from the file's dot. Five goldens change: a look at file:N now selects the line.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/look.zig')
| -rw-r--r-- | src/look.zig | 88 |
1 files changed, 67 insertions, 21 deletions
diff --git a/src/look.zig b/src/look.zig index 020aacb8..6cf01dd2 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1142,14 +1142,49 @@ pub fn followPdfLink(p: *Pardes, id: usize, probe: *const panes.Pdf.WordProbe) v } } +/// A look that found nothing: said on the message row, logged as an `err` +/// record, and marked so that /look reads back nothing (ninep/ctl.zig run). +fn missed(p: *Pardes, id: usize, comptime fmt: []const u8, args: anytype) void { + p.look_missed = true; + var said: [160]u8 = undefined; + const why = std.fmt.bufPrint(&said, fmt, args) catch "no match"; + var msg: [176]u8 = undefined; + p.setMessage(id, std.fmt.bufPrint(&msg, "Look: {s}", .{why}) catch "Look: no match"); + const serial = if (p.panes[id]) |pane| pane.serial else 0; + var rec: [200]u8 = undefined; + pardes.ctlfs.events.notePath(p, "err", std.fmt.bufPrint(&rec, "{d} look: {s}", .{ serial, why }) catch return); +} + +/// After a look at `path:N` focused its pane: a line past the end focuses +/// nothing, leaves no pane it opened, and is a miss; a bare line number +/// selects the line, its newline included, as acme's does. +fn settleLine(p: *Pardes, id: usize, path: []const u8, at: Spot, before: usize, opened: ?usize) void { + const shown = p.panes[p.active] orelse return; + const f = if (shown.file) |*file| file else return; + if (at.line > panes.File.nlines(p.gpa, f)) { + if (opened) |free| p.removePane(free, null) catch {}; + if (p.panes[before] != null) p.active = before; + return missed(p, id, "{s} has no line {d}", .{ path, at.line }); + } + if (at.line > 0 and at.col == 0 and at.end_line == 0) { + const start = modal.lineStartOffset(f.content, at.line - 1); + const next = std.mem.indexOfScalarPos(u8, f.content, start, '\n'); + const end = if (next) |i| i + 1 else f.content.len; + @import("ninep/pane.zig").setDot(shown, .{ .q0 = @intCast(start), .q1 = @intCast(end) }); + } +} + /// `file:addr` or `:addr`, acme's look.c:450-543: a colon followed by an /// address character (addr.c:28, isaddrc) that is not a line spot this /// parser already reads (`file:12`, `file:12:5`). Not a URL. fn addressed(tok: []const u8) ?struct { path: []const u8, expr: []const u8 } { if (std.mem.indexOf(u8, tok, "://") != null) return null; - if (std.mem.indexOfAny(u8, tok, " \t") != null) return null; const colon = std.mem.indexOfScalar(u8, tok, ':') orelse return null; const expr = tok[colon + 1 ..]; + // A written look is a whole line: the path has no blanks, but a + // pattern in the address may (`calc.py:/return a/`). + if (std.mem.indexOfAny(u8, tok[0..colon], " \t") != null) return null; + if (std.mem.indexOfAny(u8, expr, " \t") != null and std.mem.indexOfAny(u8, expr, "/?") == null) return null; if (expr.len == 0 or std.mem.indexOfScalar(u8, "0123456789+-/$.#,;", expr[0]) == null) return null; if (std.ascii.isDigit(expr[0])) { const pl = parsePathLine(tok); @@ -1177,12 +1212,10 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { if (path.len > 0 and (f.output != null or !std.mem.endsWith(u8, f.path, std.fs.path.basename(path)))) return; var a: Addr = .{ .text = f.content, .lim = null, .expr = expr }; const r = a.address(ninep_pane.dotOf(pane)) orelse { - var said: [128]u8 = undefined; - return p.setMessage(id, std.fmt.bufPrint(&said, "Look: {s}", .{a.err}) catch "Look: bad address"); + return missed(p, id, "{s}", .{a.err}); }; if (a.i < expr.len or r.q0 > r.q1) { - var said: [128]u8 = undefined; - return p.setMessage(id, std.fmt.bufPrint(&said, "Look: {s}", .{if (r.q0 > r.q1) "addresses out of order" else "bad address syntax"}) catch "Look: bad address"); + return missed(p, id, "{s}", .{if (r.q0 > r.q1) "addresses out of order" else "bad address syntax"}); } clearNavigationSelection(p, pane); ninep_pane.setDot(pane, r); @@ -1209,6 +1242,10 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { if (comptime pdf_enabled) if (panes.Pdf.lookSection(p, id, pl.path, pl.at)) return; var realbuf: [4096]u8 = undefined; const found = resolveLookTarget(p, id, txt, &realbuf); + // A line past the end of an open pane is a miss (the target's line is + // already clamped, so the one written is asked). + if (found == .pane and found.pane.id < MAX_PANES) if (p.panes[found.pane.id]) |shown| if (shown.file) |*f| if (pl.at.line > panes.File.nlines(p.gpa, f)) + return missed(p, id, "{s} has no line {d}", .{ trimmed, pl.at.line }); // A miss changes nothing, the selection included; anything else starts // from a clean one. if (found != .none) clearNavigationSelection(p, pane); @@ -1219,10 +1256,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { p.reportError(id, "search", err); return; }; - if (rows == 0) { - var said: [96]u8 = undefined; - return p.setMessage(id, std.fmt.bufPrint(&said, "Look: no match for \"{s}\"", .{@import("Messages.zig").clip(trimmed, 48)}) catch "Look: no match"); - } + if (rows == 0) return missed(p, id, "no match for \"{s}\"", .{@import("Messages.zig").clip(trimmed, 48)}); clearNavigationSelection(p, pane); const at = pane.search_row; _ = searchStep(p, id, 1); @@ -1235,8 +1269,10 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { .pane => |t| { if (t.id >= MAX_PANES) return; const target = p.panes[t.id] orelse return; + const before = p.active; clearNavigationSelection(p, target); focusPaneLine(p, t.id, t.at, .center); + settleLine(p, id, trimmed, t.at, before, null); }, .url => |u| if (u.len <= 256) p.emit(.{ .open_link = .from(u) }), .dir => |dir| { @@ -1267,20 +1303,30 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { exec.placeDoc(p, id, free, nt); return; }; + // An open pane on this path too short for the line: a miss that + // touches nothing. + if (openPaneTarget(p, target.path, target.at)) |open| if (p.panes[open.pane.id].?.file) |*f| + if (target.at.line > panes.File.nlines(p.gpa, f)) + return missed(p, id, "{s} has no line {d}", .{ target.path, target.at.line }); // focus an existing pane on this path (rescrolled), else open - if (focusPaneByPath(p, target.path, target.at)) return; - const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); - const nt = panes.File.open(p, free, target.path, target.at.line) catch |err| - return p.reportError(id, "look", err); - if (target.at.col > 0) nt.body.cur_col = @intCast(target.at.col - 1); - exec.placeDoc(p, id, free, nt); - layout.compute(p); - nt.file.?.scroll -|= @max(1, p.rects[free].h -| BOX_H) / 2; - if (target.at.end_line != 0) { - const centered = nt.file.?.scroll; - selectSpan(p, nt, target.at); - nt.file.?.scroll = centered; + const before = p.active; + var opened: ?usize = null; + if (!focusPaneByPath(p, target.path, target.at)) { + const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); + const nt = panes.File.open(p, free, target.path, target.at.line) catch |err| + return p.reportError(id, "look", err); + if (target.at.col > 0) nt.body.cur_col = @intCast(target.at.col - 1); + exec.placeDoc(p, id, free, nt); + layout.compute(p); + nt.file.?.scroll -|= @max(1, p.rects[free].h -| BOX_H) / 2; + if (target.at.end_line != 0) { + const centered = nt.file.?.scroll; + selectSpan(p, nt, target.at); + nt.file.?.scroll = centered; + } + opened = free; } + settleLine(p, id, target.path, target.at, before, opened); }, .image => |target| { if (focusPaneByPath(p, target.path, .{})) return; |
