summaryrefslogtreecommitdiff
path: root/src/look.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-09 02:14:21 -0300
committerGabriel Schneider <[email protected]>2026-11-09 02:21:58 -0300
commitbfb74e76ef7dfe305a26010edc86dac456034c3e (patch)
treec90744aa2e0edf37c8e6cbc0033476230a086412 /src/look.zig
parentc78d362fa20393621ac198861f891439f9d832e9 (diff)
downloadpardes-bfb74e76ef7dfe305a26010edc86dac456034c3e.tar.gz
pardes-bfb74e76ef7dfe305a26010edc86dac456034c3e.zip
locality: single-caller helpers beside their caller: File's placeOf and restoreName beside undoStep, Query's row makers (clearPlaces, makeAllRows, makeNameRows, feedGrepPlaces) beside produce, look's helpers beside lookAt, lookSpanIn and lookUnresolved, mouse's beside handleMouse and dragUpdate, normal's beside handleNormal and executeNormalAction, and the rest in Core, draw, exec, layout, main, modal, replica, syntax, terminal; Messages.printRight into draw.zig beside joinNotice and edit.spanHas into exec.zig beside operandAt, their only callers
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/look.zig')
-rw-r--r--src/look.zig186
1 files changed, 93 insertions, 93 deletions
diff --git a/src/look.zig b/src/look.zig
index e6b0c4ad..154e53bc 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -130,18 +130,6 @@ pub const Span = struct { start: usize, end: usize };
const lead_trim = "([{<\"'`*";
const trail_trim = ")]}>\"'`*,;:.!?";
-pub fn wordSpan(p: ?*pardes.Pardes, word: []const u8, cwd: []const u8, realbuf: *[4096]u8) ?Span {
- if (word.len == 0) return null;
- var lo: usize = 0;
- var hi: usize = word.len;
- while (lo < hi and std.mem.indexOfScalar(u8, lead_trim, word[lo]) != null) lo += 1;
- while (hi > lo and std.mem.indexOfScalar(u8, trail_trim, word[hi - 1]) != null) hi -= 1;
- if (lo < hi and resolve(p, word[lo..hi], cwd, realbuf) != .none) return .{ .start = lo, .end = hi };
- if (lo == 0 and hi == word.len) return null;
- if (resolve(p, word, cwd, realbuf) == .none) return null;
- return .{ .start = 0, .end = word.len };
-}
-
pub fn lineSpan(p: ?*pardes.Pardes, line: []const u8, cwd: []const u8, realbuf: *[4096]u8) ?Span {
var lo: usize = 0;
while (lo < line.len and (line[lo] == ' ' or line[lo] == '\t')) lo += 1;
@@ -313,23 +301,6 @@ pub const FileWordSpan = struct {
hi: i32, // exclusive
};
-fn noteLookSource(p: *Pardes, id: usize) void {
- const pane = p.panes[id] orelse return;
- var w: usize = 0;
- for (p.look_src[0..p.n_look_src]) |s| {
- if (s == pane.serial) continue;
- p.look_src[w] = s;
- w += 1;
- }
- if (w == p.look_src.len) {
- std.mem.copyForwards(u32, p.look_src[0 .. w - 1], p.look_src[1..w]);
- w -= 1;
- }
- p.look_src[w] = pane.serial;
- p.n_look_src = w + 1;
- p.look_walk_owner = pane.serial;
-}
-
pub fn armLookWalk(p: *Pardes, id: usize) void {
const pane = p.panes[id] orelse return;
if (pane.file) |file| if (file.content.len == 0) return;
@@ -523,30 +494,6 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, start: SearchStart,
return nrows;
}
-pub fn searchStep(p: *Pardes, id: usize, delta: i32) bool {
- const pane = p.panes[id] orelse return false;
- const rid = pane.search_pane orelse return false;
- const rp = p.panes[rid] orelse return false;
- const rf = if (rp.file) |*f| f else return false;
- // one question covers both hazards: a freed slot can be reused by an
- // unrelated pane, and a buffer of PROSE has nowhere to step to
- const tr = panes.Output.fileTraits(rf.output);
- if (!tr.steps) return false;
- // fresh results: n starts at the first row, N has nothing behind it
- const nrows: i64 = @intCast(std.mem.count(u8, rf.content, "\n") +
- @intFromBool(rf.content.len > 0 and rf.content[rf.content.len - 1] != '\n'));
- var step: i64 = if (pane.search_row) |c| @as(i64, @intCast(c)) + delta else if (delta > 0) 0 else -1;
- if (delta == 0) return true;
- const direction: i64 = if (delta > 0) 1 else -1;
- while (step >= 0 and step < nrows) : (step += direction) {
- if (!panes.Output.isResultRow(rf, @intCast(step))) continue;
- _ = jumpResult(p, id, @intCast(step));
- p.view().active = id;
- break;
- }
- return true;
-}
-
pub fn jumpResult(p: *Pardes, id: usize, row: usize) bool {
const pane = p.panes[id] orelse return false;
const rid = pane.search_pane orelse return false;
@@ -672,6 +619,18 @@ fn wholeRowSpan(ln: []const u8) ?Span {
return if (hi > lo) .{ .start = lo, .end = hi } else null;
}
+pub fn wordSpan(p: ?*pardes.Pardes, word: []const u8, cwd: []const u8, realbuf: *[4096]u8) ?Span {
+ if (word.len == 0) return null;
+ var lo: usize = 0;
+ var hi: usize = word.len;
+ while (lo < hi and std.mem.indexOfScalar(u8, lead_trim, word[lo]) != null) lo += 1;
+ while (hi > lo and std.mem.indexOfScalar(u8, trail_trim, word[hi - 1]) != null) hi -= 1;
+ if (lo < hi and resolve(p, word[lo..hi], cwd, realbuf) != .none) return .{ .start = lo, .end = hi };
+ if (lo == 0 and hi == word.len) return null;
+ if (resolve(p, word, cwd, realbuf) == .none) return null;
+ return .{ .start = 0, .end = word.len };
+}
+
fn lookSpanIn(p: *Pardes, pane: *Pane, from: LookFrom, delta: i32, budget: *usize) ?Pane.LookSpot {
const lines = edit.paneCursorLines(p, &pane.body) catch return null;
const nrows: i32 = @intCast(lines.len);
@@ -899,13 +858,6 @@ fn openPaneTarget(p: *const Pardes, path: []const u8, at: Spot) ?Target {
return null;
}
-fn focusPaneByPath(p: *Pardes, path: []const u8, at: Spot) bool {
- const target = openPaneTarget(p, path, at) orelse return false;
- clearNavigationSelection(p, p.panes[target.pane.id].?);
- focusPaneLine(p, target.pane.id, target.pane.at, .center);
- return true;
-}
-
/// Navigation starts a new selection at the destination.
pub fn clearNavigationSelection(p: *Pardes, pane: *Pane) void {
const v = p.view();
@@ -1007,20 +959,6 @@ fn missText(text: []const u8, buf: *[miss_path_cap + "…".len]u8) []const u8 {
return pardes.ctlfs.fitErr(text, buf[0..miss_path_cap]);
}
-/// A file that is there but would not open: said with its path, `look:
-/// <path>: permission denied`, the path cut in its middle when long.
-fn lookOpenFailed(p: *Pardes, id: usize, path: []const u8, err: anyerror) void {
- if (@import("Messages.zig").dialReason(err) != null) return p.reportError(id, path, err);
- var cut: [miss_path_cap + "…".len]u8 = undefined;
- // Not there, on a peer's mount as on this host: a miss, the write
- // answered, as any path to no file is.
- const remote_missing = err == error.Remote and std.mem.indexOf(u8, @import("9p_io.zig").Client.lastSaid(), "not exist") != null;
- if (err == error.FileNotFound or err == error.NotFound or remote_missing)
- return missed(p, id, "{s}: no such file", .{missText(path, &cut)});
- var said: Kind.Buf(miss_path_cap + 16) = .{};
- p.reportError(id, said.print("look: {s}", .{missText(path, &cut)}), err);
-}
-
fn missedLine(p: *Pardes, id: usize, path: []const u8, line: usize) void {
var cut: [miss_path_cap + "…".len]u8 = undefined;
missed(p, id, "{s} has no line {d}", .{ missText(path, &cut), line });
@@ -1067,25 +1005,6 @@ fn missed(p: *Pardes, id: usize, comptime fmt: []const u8, args: anytype) void {
pardes.ctlfs.events.noteErrCounted(p, rec.print("{d} look: {s}", .{ serial, why }));
}
-/// 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.view().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 |err| p.reportError(id, "look", err);
- if (p.panes[before] != null) p.view().active = before;
- return missedLine(p, id, 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) });
- }
-}
-
/// A plain word looked at in a pane, as acme's look3 does with one that
/// names no file (look.c:210, search): its next place in that pane after
/// the dot, wrapping to the top, is selected there. No +Search pane.
@@ -1124,6 +1043,30 @@ fn addressed(tok: []const u8) ?struct { path: []const u8, expr: []const u8 } {
return .{ .path = tok[0..colon], .expr = expr };
}
+pub fn searchStep(p: *Pardes, id: usize, delta: i32) bool {
+ const pane = p.panes[id] orelse return false;
+ const rid = pane.search_pane orelse return false;
+ const rp = p.panes[rid] orelse return false;
+ const rf = if (rp.file) |*f| f else return false;
+ // one question covers both hazards: a freed slot can be reused by an
+ // unrelated pane, and a buffer of PROSE has nowhere to step to
+ const tr = panes.Output.fileTraits(rf.output);
+ if (!tr.steps) return false;
+ // fresh results: n starts at the first row, N has nothing behind it
+ const nrows: i64 = @intCast(std.mem.count(u8, rf.content, "\n") +
+ @intFromBool(rf.content.len > 0 and rf.content[rf.content.len - 1] != '\n'));
+ var step: i64 = if (pane.search_row) |c| @as(i64, @intCast(c)) + delta else if (delta > 0) 0 else -1;
+ if (delta == 0) return true;
+ const direction: i64 = if (delta > 0) 1 else -1;
+ while (step >= 0 and step < nrows) : (step += direction) {
+ if (!panes.Output.isResultRow(rf, @intCast(step))) continue;
+ _ = jumpResult(p, id, @intCast(step));
+ p.view().active = id;
+ break;
+ }
+ return true;
+}
+
/// A look at text that names nothing to open: a `./` name is a missing
/// file, anything else a search for the text as written.
/// `text` is what a word search looks for: the look as written, its blanks
@@ -1483,6 +1426,63 @@ fn diffLineAddress(p: *Pardes, pane: *Pane, operand: []const u8, buf: []u8) ?[]c
return null;
}
+fn noteLookSource(p: *Pardes, id: usize) void {
+ const pane = p.panes[id] orelse return;
+ var w: usize = 0;
+ for (p.look_src[0..p.n_look_src]) |s| {
+ if (s == pane.serial) continue;
+ p.look_src[w] = s;
+ w += 1;
+ }
+ if (w == p.look_src.len) {
+ std.mem.copyForwards(u32, p.look_src[0 .. w - 1], p.look_src[1..w]);
+ w -= 1;
+ }
+ p.look_src[w] = pane.serial;
+ p.n_look_src = w + 1;
+ p.look_walk_owner = pane.serial;
+}
+
+/// 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.view().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 |err| p.reportError(id, "look", err);
+ if (p.panes[before] != null) p.view().active = before;
+ return missedLine(p, id, 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) });
+ }
+}
+
+fn focusPaneByPath(p: *Pardes, path: []const u8, at: Spot) bool {
+ const target = openPaneTarget(p, path, at) orelse return false;
+ clearNavigationSelection(p, p.panes[target.pane.id].?);
+ focusPaneLine(p, target.pane.id, target.pane.at, .center);
+ return true;
+}
+
+/// A file that is there but would not open: said with its path, `look:
+/// <path>: permission denied`, the path cut in its middle when long.
+fn lookOpenFailed(p: *Pardes, id: usize, path: []const u8, err: anyerror) void {
+ if (@import("Messages.zig").dialReason(err) != null) return p.reportError(id, path, err);
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ // Not there, on a peer's mount as on this host: a miss, the write
+ // answered, as any path to no file is.
+ const remote_missing = err == error.Remote and std.mem.indexOf(u8, @import("9p_io.zig").Client.lastSaid(), "not exist") != null;
+ if (err == error.FileNotFound or err == error.NotFound or remote_missing)
+ return missed(p, id, "{s}: no such file", .{missText(path, &cut)});
+ var said: Kind.Buf(miss_path_cap + 16) = .{};
+ p.reportError(id, said.print("look: {s}", .{missText(path, &cut)}), err);
+}
+
pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
const v = p.view();
const pane = p.panes[id] orelse return;