diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 22:49:11 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 23:38:31 -0300 |
| commit | dbff3a5bb1d47e5a348ce7e91073df43b29b3e44 (patch) | |
| tree | 02bd08fb2747a893c532651ce39d0ba6d7c67a61 | |
| parent | d03b727cddfcec41b464ddf6178f17d0e831e529 (diff) | |
| download | pardes-dbff3a5bb1d47e5a348ce7e91073df43b29b3e44.tar.gz pardes-dbff3a5bb1d47e5a348ce7e91073df43b29b3e44.zip | |
kinds #51, builtins-json lists the shipped addons' words, read off the Zig kinds' `Word` lines (image.zig and pdf.zig, handed to the generator and read by the staleness test), each `"addon"` first so the docs test's search for a builtin never meets one and an addon word the docs name is checked against the sources (renaming PdfFit fails it); the glossary says whose addon a word is, and the changelog
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
| -rw-r--r-- | build.zig | 1 | ||||
| -rw-r--r-- | docs/typ/builtins-gui.json | 5 | ||||
| -rw-r--r-- | docs/typ/builtins-tui.json | 5 | ||||
| -rw-r--r-- | docs/typ/style.typ | 3 | ||||
| -rw-r--r-- | src/CHANGELOG.md | 7 | ||||
| -rw-r--r-- | src/builtins_json.zig | 50 | ||||
| -rw-r--r-- | tools/gen_builtins_json.zig | 7 |
7 files changed, 68 insertions, 10 deletions
@@ -903,6 +903,7 @@ pub fn build(b: *std.Build) void { }) }); const run_gen = b.addRunArtifact(gen); const json = run_gen.addOutputFileArg("builtins.json"); + for ([_][]const u8{ "image/image.zig", "pdf/pdf.zig" }) |f| run_gen.addFileArg(b.path(b.fmt("addons/{s}", .{f}))); const update = b.addUpdateSourceFiles(); update.addCopyFileToSource(json, b.fmt("docs/typ/builtins-{s}.json", .{@tagName(platform)})); builtins_json_step.dependOn(&update.step); diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json index 87d98903..37b8e1ba 100644 --- a/docs/typ/builtins-gui.json +++ b/docs/typ/builtins-gui.json @@ -110,5 +110,8 @@ {"name": "Wrap", "leader": "SPC t w", "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "Long lines wrap onto the next row, on or off."}, {"name": "WsDiagnostics", "leader": "SPC l D", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the workspace's diagnostics from the language server."}, {"name": "WsSymbols", "leader": "SPC l S", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Search the workspace's symbols for its argument."}, - {"name": "Zerox", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "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)."} + {"name": "Zerox", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "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)."}, + {"addon": "pdf", "name": "PdfSections", "leader": "SPC t s", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "list the PDF's sections in a pane, each a place to go"}, + {"addon": "pdf", "name": "PdfTint", "leader": "SPC t i", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "tint the PDF to the theme or show it as printed (disabled|filtered|full)"}, + {"addon": "pdf", "name": "PdfFit", "leader": "SPC t z", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "fit the PDF's pages to the pane's width or height (width|height)"} ] diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json index c1879798..e307b3f8 100644 --- a/docs/typ/builtins-tui.json +++ b/docs/typ/builtins-tui.json @@ -103,5 +103,8 @@ {"name": "Wrap", "leader": "SPC t w", "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "Long lines wrap onto the next row, on or off."}, {"name": "WsDiagnostics", "leader": "SPC l D", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the workspace's diagnostics from the language server."}, {"name": "WsSymbols", "leader": "SPC l S", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Search the workspace's symbols for its argument."}, - {"name": "Zerox", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "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)."} + {"name": "Zerox", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "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)."}, + {"addon": "pdf", "name": "PdfSections", "leader": "SPC t s", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "list the PDF's sections in a pane, each a place to go"}, + {"addon": "pdf", "name": "PdfTint", "leader": "SPC t i", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "tint the PDF to the theme or show it as printed (disabled|filtered|full)"}, + {"addon": "pdf", "name": "PdfFit", "leader": "SPC t z", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "fit the PDF's pages to the pane's width or height (width|height)"} ] diff --git a/docs/typ/style.typ b/docs/typ/style.typ index 2f777892..bcc732a1 100644 --- a/docs/typ/style.typ +++ b/docs/typ/style.typ @@ -186,7 +186,7 @@ /// Every builtin of either build, written by `zig build builtins-json` /// from the registry and the Help rows (src/builtins_json.zig), a file per /// build: name, leader, also (Help's other shortcuts), arg, scope, setting, -/// choices, doc. Merged here, each with `platforms`: "both", "tui" (the +/// choices, doc, and for a shipped addon's word its addon first. Merged here, each with `platforms`: "both", "tui" (the /// terminal only) or "gui" (the window only). #let builtin-data = { let tui = json("builtins-tui.json") @@ -421,6 +421,7 @@ #heading(depth: 2, raw(b.name)) #label("builtin-" + b.name) #let keys = (if b.leader != none { (key(b.leader),) } else { () }) + b.also.map(shortcut) #if b.platforms != "both" [#emph(if b.platforms == "gui" [window only] else [terminal only]) · ] + #if "addon" in b [#emph[the #raw(b.addon) addon's] · ] #if keys.len() > 0 [#keys.join([, ]) · ] #if b.choices != none [#raw(b.choices.replace(", ", "|")) · ] else if b.arg [takes an argument · ] #prose(b.doc) diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 07c72846..8107f920 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -2,6 +2,13 @@ ## Unreleased +- MuPDF and FreeType are lazy: a fresh checkout's `zig build + -Dplatform=tui` fetches neither; `-Dpdf` fetches MuPDF the first time + (and is on by itself after), and without it the PDF steps say so. + The Zig kinds export `pardes_addon` from a library alone + (`addon.exportLib`), and a pardes off Linux has its addons compiled in, + as the static one does (`Addon load` there: `not on this platform`). + The glossary lists the PDF addon's words again. - The PDF addon is Zig (`addons/pdf/pdf.zig`, over MuPDF through `pdf_bridge.c`): each view of a PDF has its own layout of the one place (a terminal's text layer and a window's pages at once), its search, its diff --git a/src/builtins_json.zig b/src/builtins_json.zig index e8ec5768..c5bc6bb3 100644 --- a/src/builtins_json.zig +++ b/src/builtins_json.zig @@ -2,7 +2,9 @@ //! and builtins-gui.json, a build's list each; style.typ merges them): //! the rows the `Help` builtin draws (pardes.builtin_rows: the leader path //! and the other shortcuts) with what /commands says of each word (its doc -//! comment's first sentence, or a setting's doc). One source, so the +//! comment's first sentence, or a setting's doc), then the shipped addons' +//! words, read off their kinds' `Word` lines (`"addon"` first, so a search +//! for a builtin's `{"name": ` never meets one). One source, so the //! glossary and Help cannot drift; the test below fails when the committed //! copy is stale, and `zig build builtins-json` rewrites it. const std = @import("std"); @@ -19,7 +21,11 @@ fn lessName(_: void, a: Entry, b: Entry) bool { return std.mem.lessThan(u8, a.name, b.name); } -pub fn write(w: *std.Io.Writer) std.Io.Writer.Error!void { +/// The kinds whose words are listed (under addons/), their sources in +/// this order. +pub const addons = [_][]const u8{ "image/image.zig", "pdf/pdf.zig" }; + +pub fn write(w: *std.Io.Writer, addon_sources: []const []const u8) std.Io.Writer.Error!void { var all: [pardes.builtin_rows.len]Entry = undefined; var len: usize = 0; // This build's own frontend's words (a desktop build has the other's @@ -35,6 +41,7 @@ pub fn write(w: *std.Io.Writer) std.Io.Writer.Error!void { const row = pardes.builtin_rows[e.row]; const b = row.cmd; const name = @tagName(b); + if (n > 0) try w.writeAll(",\n"); try w.writeAll(" {\"name\": "); try str(name, .{}, w); try w.writeAll(", \"leader\": "); @@ -67,9 +74,35 @@ pub fn write(w: *std.Io.Writer) std.Io.Writer.Error!void { const doc = if (setting) |s| s.doc else ctl.summaryOf(name, &buf); try w.writeAll(", \"doc\": "); try str(doc, .{}, w); - try w.writeAll(if (n + 1 < order.len) "},\n" else "}\n"); + try w.writeByte('}'); + } + // A kind's word is a line of its own: `.{ .name = "PdfFit", .leader = + // "tz", .arg = .optional, .doc = "..." },` (a doc's Zig escapes are + // copied as written: none has one). + for (addon_sources) |source| { + var kind: []const u8 = ""; + var lines = std.mem.splitScalar(u8, source, '\n'); + while (lines.next()) |line| { + if (std.mem.indexOf(u8, line, "pub const head: addon.Head = ") != null) kind = quoted(line, ".name = ").?; + if (!std.mem.startsWith(u8, std.mem.trimStart(u8, line, " "), ".{ .name = \"")) continue; + try w.print(",\n {{\"addon\": \"{s}\", \"name\": \"{s}\", \"leader\": ", .{ kind, quoted(line, ".name = ").? }); + if (quoted(line, ".leader = ")) |l| { + try w.writeAll("\"SPC"); + for (l) |c| try w.print(" {c}", .{c}); + try w.writeByte('"'); + } else try w.writeAll("null"); + try w.print(", \"also\": [], \"arg\": {}, \"scope\": \"pane\", \"setting\": false, \"choices\": null, \"doc\": ", .{std.mem.indexOf(u8, line, ".arg = .") != null}); + try str(quoted(line, ".doc = ") orelse "", .{}, w); + try w.writeByte('}'); + } } - try w.writeAll("]\n"); + try w.writeAll("\n]\n"); +} + +/// The string after `field` on a line: `.name = "PdfFit"` is PdfFit. +fn quoted(line: []const u8, comptime field: []const u8) ?[]const u8 { + const at = (std.mem.indexOf(u8, line, field ++ "\"") orelse return null) + field.len + 1; + return line[at .. std.mem.indexOfScalarPos(u8, line, at, '"') orelse return null]; } test "docs/typ/builtins-<platform>.json is what the registry says now" { @@ -84,7 +117,14 @@ test "docs/typ/builtins-<platform>.json is what the registry says now" { const gpa = std.testing.allocator; var out: std.Io.Writer.Allocating = .init(gpa); defer out.deinit(); - try write(&out.writer); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + var sources: [addons.len][]const u8 = undefined; + for (addons, &sources) |path, *source| { + var buf: [4096]u8 = undefined; + source.* = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, try std.fmt.bufPrint(&buf, "{s}/{s}", .{ @import("doc_typ").addons, path }), arena.allocator(), .limited(1 << 20)); + } + try write(&out.writer, &sources); var dir = try std.Io.Dir.cwd().openDir(std.testing.io, @import("doc_typ").dir, .{}); defer dir.close(std.testing.io); const committed = try dir.readFileAlloc(std.testing.io, file, gpa, .limited(1 << 20)); diff --git a/tools/gen_builtins_json.zig b/tools/gen_builtins_json.zig index 3158c8b2..35dc49dc 100644 --- a/tools/gen_builtins_json.zig +++ b/tools/gen_builtins_json.zig @@ -1,14 +1,17 @@ //! Writes every builtin as JSON to the path given (docs/typ/builtins-<tui|gui>.json, -//! by way of `zig build builtins-json`). +//! by way of `zig build builtins-json`), then the words of the addons whose +//! sources follow it (builtins_json.addons, in that order). const std = @import("std"); const pardes = @import("pardes"); pub fn main(init: std.process.Init) !void { const args = try init.minimal.args.toSlice(init.arena.allocator()); + var sources: [pardes.builtins_json.addons.len][]const u8 = undefined; + for (&sources, args[2..][0..sources.len]) |*source, path| source.* = try std.Io.Dir.cwd().readFileAlloc(init.io, path, init.arena.allocator(), .limited(1 << 20)); var file = try std.Io.Dir.cwd().createFile(init.io, args[1], .{}); defer file.close(init.io); var buf: [4096]u8 = undefined; var w = file.writer(init.io, &buf); - try pardes.builtins_json.write(&w.interface); + try pardes.builtins_json.write(&w.interface, &sources); try w.interface.flush(); } |
