diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:42:22 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-04 23:42:22 -0300 |
| commit | 5a927d1a4e92750bc0d48994df2c2e552d669b01 (patch) | |
| tree | 7301943c90d813a561400468967e774c39c6d376 | |
| parent | 63e6ceefc7ab33e31c9d4f83387183e44089e443 (diff) | |
| download | pardes-5a927d1a4e92750bc0d48994df2c2e552d669b01.tar.gz pardes-5a927d1a4e92750bc0d48994df2c2e552d669b01.zip | |
exec, look: pointerOperand, isFile and langOf, one-line wrappers with one caller or four, go to their callers (pardes.zig's recentKeeps asks kindOf), as do the unused themes, BOX_H and pathUnder and look's second alias of fs.zig; missedLine and lookPdfPage take their one type, not anytype; isRecentList drops a .cmd = .Recent origin nothing makes; executeFrom's doc moves off isComment, and a comment look.zig said twice is said once
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
| -rw-r--r-- | src/exec.zig | 26 | ||||
| -rw-r--r-- | src/look.zig | 26 | ||||
| -rw-r--r-- | src/mouse.zig | 2 | ||||
| -rw-r--r-- | src/ninep/events.zig | 2 | ||||
| -rw-r--r-- | src/pardes.zig | 2 |
5 files changed, 19 insertions, 39 deletions
diff --git a/src/exec.zig b/src/exec.zig index 3fc03038..de31624a 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -13,7 +13,6 @@ const normal = @import("normal.zig"); const edit = @import("edit.zig"); const body_layer = @import("body_layer.zig"); const colors = @import("colors.zig"); -const themes = colors.themes; const builtins = @import("builtins.zig"); const config = @import("config.zig"); const grammars = @import("grammar_manifest.zig").all; @@ -27,7 +26,6 @@ const hosted = pardes.hosted; const fonts = pardes.fonts; const Pane = panes.Pane; const MAX_COLS = pardes.MAX_COLS; -const BOX_H = pardes.BOX_H; const Builtin = pardes.Builtin; const Key = pardes.Key; const sel_slot = pardes.sel_slot; @@ -103,10 +101,6 @@ pub const PointerOperand = struct { expanded: ?Pane.Sel = null, }; -pub fn pointerOperand(p: *Pardes, pane: *Pane, clicked: Pane.Sel) PointerOperand { - return operandAt(p, pane, clicked, true, true); -} - /// The body's explicit selection, else what a look at its cursor takes. pub fn currentOperand(p: *Pardes, pane: *Pane) ?[]const u8 { if (pane.file == null and !pane.isTerminal()) return null; @@ -458,11 +452,6 @@ pub fn missingDir(p: *Pardes, dir: []const u8) bool { return kindOf(local) != .directory; } -/// Whether `path` is a plain file on this host, the turn out while it asks. -pub fn isFile(path: []const u8) bool { - return kindOf(path) == .file; -} - /// What `path` is on this host, null when it is not there; the turn out /// while it asks (it may be inside a mount this editor serves). pub fn kindOf(path: []const u8) ?std.Io.File.Kind { @@ -514,12 +503,6 @@ pub fn evictLonePristineTty(p: *Pardes, col: usize, keep_id: usize) void { // a word like `ls` too. The tag's words, `Exec` by name and a command word // `@`...`` still run as commands. -/// A file pane's language, as grammar_manifest names it, by its index. -pub fn langOf(pane: *const Pane) ?u8 { - const f = pane.file orelse return null; - return @intCast(@import("grammar_manifest.zig").byPath(f.path) orelse return null); -} - /// A bound REPL whose program is there to take input: a command pane's /// while its command runs; an interactive terminal's while a program, not /// the shell, has its tty (the host's `tty_taken`) -- a python3 left with @@ -557,7 +540,8 @@ fn routeToRepl(p: *Pardes, from: usize, text: []const u8) Routed { sendToRepl(p, from, from, text); return .{ .sent = from }; } - const lang = langOf(src) orelse return .none; + // The file's language, by its grammar_manifest index. + const lang: u8 = @intCast(@import("grammar_manifest.zig").byPath((src.file orelse return .none).path) orelse return .none); // Every REPL bound for the language whose program still runs: one // whose program exited is skipped, in the question and in the choice. var bound: [26]usize = undefined; @@ -710,9 +694,6 @@ pub fn execute(p: *Pardes, id: usize, txt: []const u8) ?usize { return executeFrom(p, id, txt, false); } -/// `execute` for text a gesture took from `id`'s body when `from_body`: -/// such text may be a bound REPL's. Run by name (`Exec ...`, whose line -/// comes back through `execute`) or written as a command word, never. /// A line that starts with `#` is a comment, as in a shell: it runs as /// nothing, silently, wherever a line runs (exec, a ctl, the init file), /// so DumpConfig's report reads back as configuration whole. @@ -721,6 +702,9 @@ pub fn isComment(line: []const u8) bool { return t.len > 0 and t[0] == '#'; } +/// `execute` for text a gesture took from `id`'s body when `from_body`: +/// such text may be a bound REPL's. Run by name (`Exec ...`, whose line +/// comes back through `execute`) or written as a command word, never. pub fn executeFrom(p: *Pardes, id: usize, txt: []const u8, from_body: bool) ?usize { if (isComment(commandText(txt))) return null; // An empty window runs its session words, and a command line in the diff --git a/src/look.zig b/src/look.zig index f8c1e24b..05cdd581 100644 --- a/src/look.zig +++ b/src/look.zig @@ -5,9 +5,8 @@ const pardes = @import("pardes.zig"); const exec = @import("exec.zig"); const config = @import("config.zig"); const pdf_enabled = @import("pardes_config").mupdf; -const fs = @import("fs.zig"); const diff = @import("diff.zig"); -const platform_has_fs = fs.platform_has_fs; +const platform_has_fs = filesystem.platform_has_fs; const layout = @import("layout.zig"); const animation = @import("animation.zig"); const modal = @import("modal.zig"); @@ -26,7 +25,6 @@ const Layer = @import("Layer.zig"); const TagHit = pardes.TagHit; const BOX_H = pardes.BOX_H; const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET; -const pathUnder = pardes.pathUnder; const Mouse = pardes.Mouse; const Key = pardes.Key; const Event = pardes.Event; @@ -372,7 +370,7 @@ pub fn resolve(p: ?*pardes.Pardes, word_raw: []const u8, cwd: []const u8, realbu if (std.mem.startsWith(u8, trimmed, scheme)) return .{ .url = trimmed }; } - const found = fs.resolve(p, word, cwd, realbuf) orelse return .none; + const found = filesystem.resolve(p, word, cwd, realbuf) orelse return .none; if (found.dir) return .{ .dir = found.path }; if (comptime pdf_enabled) if (isPdfPath(found.path)) return .{ .file = .{ .path = found.path, @@ -979,7 +977,7 @@ pub fn advanceLookHover(p: *Pardes) void { pane.pdf.?.invalidateRaster(probe.page); return; }; - const operand = exec.pointerOperand(p, pane, pointed.sel); + const operand = exec.operandAt(p, pane, pointed.sel, true, true); if (operand.text == null or operand.text.?.len == 0) { p.look_hover_refused = waiting.*; return cancelLookHover(p); @@ -1255,7 +1253,7 @@ fn pdfPaneOf(p: *Pardes, path: []const u8) ?*panes.Pdf.State { return null; } -fn missedLine(p: *Pardes, id: usize, path: []const u8, line: anytype) void { +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 }); } @@ -1535,7 +1533,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { /// miss, and `:N:H` to page N's search hit H, as `book.pdf:N:H` (a PDF /// search's row) does. It has no text to hold a byte offset (`#N`) or a /// pattern: any other address is refused with what it takes. -fn lookPdfPage(p: *Pardes, id: usize, target: usize, pv: anytype, expr: []const u8) void { +fn lookPdfPage(p: *Pardes, id: usize, target: usize, pv: *panes.Pdf.State, expr: []const u8) void { var cut: [miss_path_cap + "…".len]u8 = undefined; const trimmed = std.mem.trim(u8, expr, " \t"); const colon = std.mem.indexOfScalar(u8, trimmed, ':') orelse trimmed.len; @@ -1645,14 +1643,14 @@ pub fn reopenAt(p: *Pardes, from: usize, path: []const u8, at: Spot) void { } } -/// Whether `pane` is the +Recent or the Jumplist list, whose rows are -/// remembered places: a look at one clamps to the file as it is now. +/// Whether `pane` is the Recent query pane or the Jumplist list, whose rows +/// are remembered places: a look at one clamps to the file as it is now. fn isRecentList(pane: *const Pane) bool { // A query pane over the recent files: its rows are remembered places. if (pane.query) |q| if (q.source == .recent) return true; const f = pane.file orelse return false; const o = f.output orelse return false; - return std.meta.eql(o.from, panes.Output.Origin{ .cmd = .Recent }) or std.meta.eql(o.from, panes.Output.Origin{ .cmd = .Jumplist }); + return std.meta.eql(o.from, panes.Output.Origin{ .cmd = .Jumplist }); } // ---- a look on a diff line ---- @@ -1770,8 +1768,6 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { if (comptime pdf_enabled) if (pane.hasPdf() and trimmed.len > 1 and trimmed[0] == ':') return lookAddress(p, id, "", trimmed[1..]); const pl = parsePathLine(trimmed); - // `file:3:0`: columns count from 1, as addr's do, and a zero is refused - // in addr's words rather than taken as no column. if (comptime pdf_enabled) if (pane.hasPdf()) clearNavigationSelection(p, pane); if (comptime pdf_enabled) if (panes.Pdf.lookSection(p, id, pl.path, pl.at)) return; var realbuf: [4096]u8 = undefined; @@ -2371,7 +2367,7 @@ test "Look on a diff: headers and a hunk line's prefix are the whole line, hover const y = p.bodyTop(pane, rect) + at.row; // The hover's span is the click's operand. const pointed = edit.pointerTextSelection(p, 0, x, y, null, null) orelse return error.NothingPointed; - const operand = exec.pointerOperand(p, pane, pointed.sel); + const operand = exec.operandAt(p, pane, pointed.sel, true, true); const lines = diffLines(p, pane).?; // scratch: good until the next update const span = operand.file_word orelse return error.NoHoverSpan; try std.testing.expectEqual(@as(i32, at.row), span.row); @@ -2446,7 +2442,7 @@ test "a click, a 9P whole-line look and an empty event write-back take one expan const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane) + at.col; const y = p.bodyTop(pane, rect) + at.row; const pointed = edit.pointerTextSelection(p, 0, x, y, null, null) orelse return error.NothingPointed; - const clicked = exec.pointerOperand(p, pane, pointed.sel).text orelse return error.NothingClicked; + const clicked = exec.operandAt(p, pane, pointed.sel, true, true).text orelse return error.NothingClicked; try std.testing.expectEqualStrings(at.want, clicked); // An empty record written back to event, at the same byte. const body = pane.file.?.content; @@ -2719,7 +2715,7 @@ test "Look outside a diff pane expands and looks as ever" { const rect = p.rects[0]; const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane) + 0; const pointed = edit.pointerTextSelection(p, 0, x, p.bodyTop(pane, rect) + 2, null, null).?; - const operand = exec.pointerOperand(p, pane, pointed.sel); + const operand = exec.operandAt(p, pane, pointed.sel, true, true); try std.testing.expect(operand.text == null or !std.mem.eql(u8, operand.text.?, "+const a = 1;")); } diff --git a/src/mouse.zig b/src/mouse.zig index c1ea598d..4e0439fa 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -1091,7 +1091,7 @@ fn gestureRange(p: *Pardes, id: usize, text: []const u8, on_tag: bool, operand: .{ .row = @intCast(@max(0, w.row)), .col = @intCast(@max(0, w.lo)) } else if (operand.expanded orelse operand.preview) |sel| lead: { // A selection's start in reading order, converted the way - // `pointerOperand` converts the click itself. + // `operandAt` converts the click itself. const lead = edit.sweepEnds(sel)[0]; const top = lead[0] - @as(i32, pane.tag_rows); if (top < 0) break :lead null; diff --git a/src/ninep/events.zig b/src/ninep/events.zig index f24c6120..68f9f3e7 100644 --- a/src/ninep/events.zig +++ b/src/ninep/events.zig @@ -726,7 +726,7 @@ fn scanNumber(data: []const u8, i: *usize, overflow: *bool) ?u32 { /// The word a click at `at` expands to: the file name or word run under it /// on its line (look.expandedWord), else nothing. /// An empty range written back: what a click at `at` takes, as the mouse's -/// does (exec.pointerOperand). In a diff pane's body that is look.diffClick's +/// does (exec.operandAt). In a diff pane's body that is look.diffClick's /// answer, the line's address or its code's words. /// `for_look`: only a look in a body takes a diff line's address /// (exec.operandAt); an exec takes the word there, as anywhere. diff --git a/src/pardes.zig b/src/pardes.zig index ba373726..aa458198 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -4466,7 +4466,7 @@ pub const Pardes = struct { pub fn recentKeeps(path: []const u8) bool { const local = filesystem.localPath(path) orelse return false; if (comptime !hosted) return true; - return exec.isFile(local); + return exec.kindOf(local) == .file; } /// A file, PDF or image pane closing: its place noted in Recent, when |
