summaryrefslogtreecommitdiff
path: root/core/builtins.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 15:14:44 -0300
committerGabriel Schneider <[email protected]>2026-11-23 15:47:11 -0300
commit33b1f209162f94a9200f8c00d131aae772eb02f2 (patch)
tree9bb64b28ec984326939aa42952ffd3dd34d0a4dc /core/builtins.zig
parentf34d3a74cc4a6b735c98ce98cef0df42bd065e67 (diff)
downloadpardes-33b1f209162f94a9200f8c00d131aae772eb02f2.tar.gz
pardes-33b1f209162f94a9200f8c00d131aae772eb02f2.zip
help: a builtin's documentation is the `///` block right above its `pub const <Word> = struct`, read at compile time into one table, `registry.doc` (its summary, the first sentence, and all of it, a line a paragraph), and every reader takes the table (the user's words of 2026-11-23: "the builtins should have their documentation in code somewhere (you may use comptime to extract that) near their definitions"): the summary was found at run time, each word's by a scan of the embedded source for `\npub const <Word> = struct` (core/ninep/ctl.zig `summaryOf`), `stripCitations` cutting `(exec.c:892)` and the like out of it: both are deleted; THE CONVENTION is written at the top of core/builtins.zig (the `///` above a builtin is what a user reads in Help, `pardes help`, /commands, `pardes words` and the glossary; no file names, no "registration", no history; notes for the code's reader are `//` lines inside the struct) and the compiler holds what it can read of it: a builtin with no `///` block, a first sentence over `summary_max` (100 bytes) or a `///` naming a .zig file fails the build, naming the builtin (one pass over the source, `registry.docs`; a setting's documentation is its `Setting.doc`, held the same); 35 builtins' docs cut to it (a first sentence over 100 bytes split at a sentence, acme and source citations into `//` notes in the struct), and DumpDir's setting doc (core/config.zig) the same; /commands prints each word's summary whole (no clip: the bound holds it); the docs' JSON (core/builtins_json.zig) takes `doc` from the table and gains `text`, the whole documentation, beside it (an addon's word: its one `.doc` in both); docs/typ/builtins-tui.json regenerated (`zig build builtins-json -Dplatform=tui`; builtins-gui.json in the change that runs the window's gates); tests: builtins.zig "a builtin's documentation is the whole `///` block above it, a line a paragraph, its summary first", ctl.zig "every word's /commands description is its documentation's summary, a line" (replacing the source-scanning one); core-test 942/1108 (166 skipped; the base measures 941/1107 here, see the report), Debug, tui, load 2-7
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/builtins.zig')
-rw-r--r--core/builtins.zig428
1 files changed, 332 insertions, 96 deletions
diff --git a/core/builtins.zig b/core/builtins.zig
index 51f22bcb..b7e1a111 100644
--- a/core/builtins.zig
+++ b/core/builtins.zig
@@ -1,4 +1,15 @@
//! Command structs and runtime settings form the builtin registry; bindings live in config.zig.
+//!
+//! THE CONVENTION: the `///` block right above a builtin's `pub const
+//! <Word> = struct` is what a USER reads, in Help, `pardes help`, /commands,
+//! `pardes words` and the manual's glossary (`registry.doc`): what the word
+//! does, its argument's forms as typed, what it does bare, where its answer
+//! goes, an example where the forms are not obvious. No file names, no
+//! "registration", no history: notes for whoever reads the code are `//`
+//! lines inside the struct. Its first sentence (to the first `. `) is the
+//! summary, at most `summary_max` bytes; a blank `///` starts a paragraph.
+//! The compiler holds it: a builtin with no `///`, a summary past the bound
+//! or a `///` naming a .zig file fails the build, naming the builtin.
const std = @import("std");
const pardes = @import("root.zig");
const tagline = @import("tagline.zig");
@@ -152,6 +163,46 @@ pub fn word(comptime T: type) []const u8 {
return n[dot + 1 ..];
}
+/// A builtin's documentation (THE CONVENTION, at the top of this file).
+pub const Doc = struct {
+ /// Its first sentence: a line of /commands and of `pardes words`.
+ summary: []const u8,
+ /// All of it, a line a paragraph, the summary first.
+ text: []const u8,
+};
+
+/// The longest summary, in bytes: a line's worth after its word.
+pub const summary_max = 100;
+
+/// `text`'s first sentence: to the first `.` a blank or a line's end
+/// follows (`a.zig@main` and `from..to` go on).
+fn docOf(comptime text: []const u8) Doc {
+ for (text, 0..) |c, i| {
+ if (c == '\n') return .{ .summary = text[0..i], .text = text };
+ if (c == '.' and (i + 1 == text.len or text[i + 1] == ' ' or text[i + 1] == '\n')) return .{ .summary = text[0 .. i + 1], .text = text };
+ }
+ return .{ .summary = text, .text = text };
+}
+
+/// The `///` lines from `from` to `to` in `source` as paragraphs: each
+/// line's text after `///` joined to the next by a blank, a blank `///` a
+/// line break.
+fn paragraphs(comptime source: []const u8, comptime from: usize, comptime to: usize) []const u8 {
+ var text: []const u8 = "";
+ var lines = std.mem.splitScalar(u8, source[from..to], '\n');
+ var gap: []const u8 = "";
+ while (lines.next()) |line| {
+ const said = std.mem.trim(u8, line["///".len..], " ");
+ if (said.len == 0) {
+ if (text.len > 0) gap = "\n";
+ continue;
+ }
+ text = text ++ (if (text.len == 0) "" else if (gap.len > 0) gap else " ") ++ said;
+ gap = "";
+ }
+ return text;
+}
+
pub const OutputTraits = struct {
name: []const u8,
steps: bool = false,
@@ -204,6 +255,63 @@ pub const registry = struct {
return setting;
}
+ /// What a user reads of builtin `b` (THE CONVENTION, at the top).
+ pub fn doc(b: Builtin()) Doc {
+ return docs[@backingInt(b)];
+ }
+
+ /// Each builtin's documentation, by its number: a hand-written one's
+ /// the `///` block above it, read off this file at compile time; a
+ /// setting's its `doc`.
+ const docs = docs: {
+ const manual = manualBuiltinList();
+ const generated = settingList();
+ var table: [manual.len + generated.len]Doc = undefined;
+ var found: [manual.len]bool = @splat(false);
+ // a few branches a byte of the source, once
+ @setEvalBranchQuota(4_000_000);
+ const source = @embedFile("builtins.zig");
+ var block: ?usize = null; // where the `///` lines above this one start
+ var block_end: usize = 0;
+ var at: usize = 0;
+ while (at < source.len) {
+ const end = std.mem.indexOfScalarPos(u8, source, at, '\n') orelse source.len;
+ const line = source[at..end];
+ if (std.mem.startsWith(u8, line, "///")) {
+ if (block == null) block = at;
+ block_end = end;
+ } else {
+ if (block) |from| if (std.mem.startsWith(u8, line, "pub const ")) {
+ const rest = line["pub const ".len..];
+ if (std.mem.indexOf(u8, rest, " = struct")) |name_end| for (manual, 0..) |T, i| {
+ if (!std.mem.eql(u8, word(T), rest[0..name_end])) continue;
+ table[i] = docOf(paragraphs(source, from, block_end));
+ found[i] = true;
+ };
+ };
+ block = null;
+ }
+ at = end + 1;
+ }
+ for (manual, 0..) |T, i| {
+ if (!found[i]) @compileError("builtin " ++ word(T) ++ " has no documentation: a `///` block right above `pub const " ++ word(T) ++ " = struct`");
+ held(word(T), table[i]);
+ }
+ for (generated, manual.len..) |setting, i| {
+ table[i] = docOf(setting.doc);
+ held(setting.word, table[i]);
+ }
+ break :docs table;
+ };
+
+ /// THE CONVENTION's two rules the compiler can read.
+ fn held(comptime name: []const u8, comptime d: Doc) void {
+ if (d.summary.len > summary_max)
+ @compileError(std.fmt.comptimePrint("builtin {s}: its first sentence is {d} bytes, over {d}: \"{s}\"", .{ name, d.summary.len, summary_max, d.summary }));
+ if (std.mem.indexOf(u8, d.text, ".zig") != null)
+ @compileError("builtin " ++ name ++ ": its documentation names a source file; a note for the code's reader is a `//` line inside the struct");
+ }
+
pub fn takesArg(b: Builtin()) bool {
// Every setting takes its value, and a switch flips when bare.
return declOr(b, "takes_arg", false, true);
@@ -394,10 +502,12 @@ pub fn warnModifiedIn(c: Ctx, asking: Pane.Discarding, which: Asked) bool {
return count > 0;
}
-/// Quit the editor, refusing once while a pane holds unsaved text: an Exit
-/// with nothing edited since discards it (acme's Exit, editors/acme/exec.c:892,
-/// asking warnModified first).
+/// Quit the editor; refused once while a pane holds unsaved text.
+///
+/// Each pane with unsaved text is listed in +Unsaved and the notice counts
+/// them; Exit again, nothing edited since, quits and discards it.
pub const Exit = struct {
+ // acme's Exit (editors/acme/exec.c:892), asking warnModifiedIn first.
pub const scope: Scope = .session;
pub fn run(c: Ctx) void {
if (warnModifiedIn(c, .Exit, .all)) return;
@@ -406,14 +516,16 @@ pub const Exit = struct {
}
};
-/// acme's Kill (exec.c, `kill`; acme.c's WKill): stop the commands pardes
-/// started -- the lines it typed into a terminal, from an exec, a middle
-/// click or a pty/run, while their shell says they run (C mark to D).
-/// Bare, every one; `Kill make ls`, those whose line starts with one of
-/// the words. acme posts the "kill" note, which ends a process; here that
-/// is SIGTERM to the terminal's foreground job, and never to the shell,
-/// which is its own job and stays.
+/// Stop the commands pardes started that are still running.
+///
+/// They are the lines pardes typed into a terminal (from an exec, a middle
+/// click, a pty/run) while their shell says they run. Bare, every one; `Kill
+/// make ls`, those whose line starts with one of the words. Each gets
+/// SIGTERM, sent to its terminal's foreground job, never to the shell, which
+/// stays.
pub const Kill = struct {
+ // acme's Kill (exec.c, `kill`; acme.c's WKill) posts the "kill" note,
+ // which ends a process; here a terminal's job between its C and D marks.
pub const scope: Scope = .session;
pub const takes_arg = true;
pub fn run(c: Ctx) void {
@@ -462,7 +574,8 @@ pub const Kill = struct {
}
};
-/// Write the session's panes and layout to the state file, for Restore;
+/// Write the session's panes and layout to the state file, for Restore.
+///
/// `Dump export <path>` writes them to a file of their own instead.
pub const Dump = struct {
pub const scope: Scope = .session;
@@ -481,8 +594,11 @@ pub const Dump = struct {
}
};
-/// Replace every pane with those of a dump: the state file's of that label,
-/// or a file's; bare, the last one this session made, else the newest.
+/// Replace every pane with those of a dump.
+///
+/// `Restore <label>`: the state file's dump of that label; `Restore <file>`:
+/// a dump file's. Bare: the last one this session made, else the newest.
+/// Refused once while a pane holds unsaved text, as Exit is.
pub const Restore = struct {
pub const scope: Scope = .session;
pub const takes_arg = true;
@@ -532,7 +648,9 @@ pub const Restore = struct {
};
/// Detach this pardes from its terminal or window, leaving the session
-/// running: `pardes attach` (or `pardes-gui attach`) shows it as a client.
+/// running.
+///
+/// `pardes attach` (or `pardes-gui attach`) shows it again, as a client.
pub const Detach = struct {
pub const scope: Scope = .session;
pub const enabled = pardes.can_attach;
@@ -541,8 +659,10 @@ pub const Detach = struct {
}
};
-/// Take in the shells of a session that died holding them, each as a
-/// terminal pane here: the pardes daemon kept their terminals open.
+/// Take in the shells of a session that died holding them, each as a terminal
+/// here.
+///
+/// The pardes daemon kept their terminals open.
pub const Adopt = struct {
pub const scope: Scope = .session;
pub const enabled = pardes.can_attach;
@@ -551,9 +671,10 @@ pub const Adopt = struct {
}
};
-/// Move this session onto the pardes installed since it started, in place:
-/// its text, undo, views, terminals with their running shells, and its
-/// terminals and windows come along. The pardes daemon moves too.
+/// Move this session onto the pardes installed since it started, in place.
+///
+/// Its text, undo, views, terminals with their running shells, and its
+/// terminals and windows come along; the pardes daemon moves too.
pub const Upgrade = struct {
pub const scope: Scope = .session;
pub const enabled = pardes.can_attach;
@@ -728,8 +849,10 @@ fn stateArg(c: Ctx, comptime T: type, comptime builtin_word: []const u8, comptim
const OnOff = enum { on, off };
-/// Addons, the libraries that bring kinds of pane: `Addon load <path>`,
-/// `Addon unload <name>`, `Addon reload <name>`; bare, the kinds here.
+/// Load, unload or reload an addon, a library that brings a kind of pane.
+///
+/// `Addon load <path>`, `Addon unload <name>`, `Addon reload <name>`; bare,
+/// the kinds here.
pub const Addon = struct {
pub const scope: Scope = .session;
pub const takes_arg = true;
@@ -738,8 +861,11 @@ pub const Addon = struct {
}
};
-/// glyph art over the host's pixels: an image pane's picture, or the
-/// kitty graphics a terminal's program placed (yazi's previews)
+/// Draw an image pane's picture, or a terminal's kitty graphics, as glyph
+/// art.
+///
+/// `Petscii on` or `Petscii off` sets it; bare, it flips. A terminal's kitty
+/// graphics are the pictures its program placed (yazi's previews).
pub const Petscii = struct {
pub const needs: PaneKind = .picture;
pub const takes_arg = true;
@@ -861,10 +987,12 @@ pub const Get = struct {
}
};
-/// acme's Putall: every pane holding unsaved edits to a file is saved, each
-/// as its own Save; one that is refused (changed on disk since, a write
-/// that fails) says so and the rest are saved all the same.
+/// Save every pane holding unsaved edits to a file, each as its own Save.
+///
+/// One that is refused (changed on disk since, a write that fails) says so,
+/// and the rest are saved all the same.
pub const Putall = struct {
+ // acme's Putall.
pub const scope: Scope = .session;
pub fn run(c: Ctx) void {
for (c.p.panes, 0..) |slot, id| {
@@ -880,10 +1008,13 @@ pub const Putall = struct {
}
};
-/// acme's Incl, for the session: `Incl dir ...` adds directories a look at a
-/// name found nowhere else is tried in (`stdio.h`, `<foo.h>`), bare lists
-/// them, `Incl -` empties the list.
+/// Add directories where a Look tries a name it finds nowhere else
+/// (`stdio.h`, `<foo.h>`).
+///
+/// `Incl <dir> ...` adds them, each absolute or from `~`; bare, it lists
+/// them; `Incl -` empties the list. The list is the session's.
pub const Incl = struct {
+ // acme's Incl, for the session.
pub const scope: Scope = .session;
pub const takes_arg = true;
pub fn run(c: Ctx) void {
@@ -935,9 +1066,11 @@ pub const Incl = struct {
}
};
-/// Open the plumbing file, the plumber's rules (plumb(6)'s rule sets) in
-/// the configuration directory beside `init`: saved, they are the rules in
-/// force. Not there yet, it holds `include basic`, the default rules.
+/// Open the plumbing file, the plumber's rules, in the configuration
+/// directory beside `init`.
+///
+/// Saved, they are the rules in force (plumb(6)'s rule sets). Not there yet,
+/// it holds `include basic`, the default rules.
pub const Plumb = struct {
pub const scope: Scope = .session;
pub const takes_arg = true;
@@ -950,9 +1083,12 @@ pub const Plumb = struct {
}
};
-/// 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).
+/// Open a second pane on this pane's file: the same text, undo and unsaved
+/// state.
+///
+/// Each pane keeps a scroll and a cursor of its own.
pub const Zerox = struct {
+ // acme's Zerox (File.zerox).
pub fn run(c: Ctx) void {
if (@import("edit_cmd.zig").busyOn(c.p, c.id)) return c.p.reportFailure(c.id, "Zerox: " ++ @import("edit_cmd.zig").e_busy);
const f = c.pane.file orelse return c.p.reportFailure(c.id, "Zerox: only a file pane takes it");
@@ -1057,7 +1193,10 @@ pub const Del = struct {
}
};
-/// Recolour a terminal's or a +Pager's program colours to the theme, or show them as sent, flipping between them.
+/// Recolour a terminal's or a +Pager's program colours to the theme, or show
+/// them as sent.
+///
+/// Each Filter flips between the two.
pub const Filter = struct {
pub const needs: PaneKind = .program_colors;
pub fn run(c: Ctx) void {
@@ -1074,34 +1213,80 @@ pub const Syntax = struct {
}
};
-/// Show a file as it was at revision `rev` (jj), read-only, beside its pane; in such a pane, that file at another revision in its place, or bare, the file.
+/// Show this file as it was at a jj revision, read-only, beside its pane.
+///
+/// `At <rev>` (`At main`, `At @-`) opens `path@rev`, as a Look at that name
+/// does. In such a pane, `At <rev>` turns it to that revision, the cursor's
+/// line kept, and bare `At` opens the file itself. What jj refuses is said in
+/// jj's words.
pub const At = struct {
pub const takes_arg = true;
pub const run = @import("jj.zig").word;
};
-/// Pin the changes `revset` names (jj) on a file's pane and show them in this view: a lane each after the line number, a line one added whole green, what the file no longer has drawn where it stood (ghost rows: a line taken away whole red, each change's description after its last line); bare, shown here or not (none pinned yet: `@`).
+/// Draw jj's changes to this file on its own pane: a lane each, and what they
+/// took away.
+///
+/// `Changes <revset>` pins the revset's changes that touched the file on its
+/// pane, or a revision's (`notes.md@main`), and shows them in this view:
+/// `Changes @-::@`, `Changes trunk()..@`. One set a pane: a later Changes or
+/// Compare replaces it. Bare: hidden in this view, or shown again; with none
+/// pinned yet, `@`.
+///
+/// Each change gets a lane after the line number. What the file no longer has
+/// is drawn where it stood, rows with no number, and after a change's last
+/// line its description, `id title author age`, its lane ending in an arrow
+/// at it. `] g` and `[ g` step through the changes; B3 on a description's id
+/// opens that change's patch at that line (`Diff <id> <path>:<line>`).
pub const Changes = struct {
pub const takes_arg = true;
pub const run = @import("jj.zig").changesWord;
};
-/// Pin on a file's pane the file's whole difference between each two of `points` (jj revisions, a blank between, two or more) as one change, however many changes lie between them, and show them in this view as `Changes` shows a change: a lane each, the lines it wrote and took away, its row `from..to N changes dates` after its last line; bare, as bare `Changes`.
+/// Draw the file's difference between each two jj revisions as one change, as
+/// Changes draws one.
+///
+/// `Compare <rev> <rev> [<rev> ...]`: two points or more in their order, each
+/// one revision (a commit or change id, a bookmark, `master@origin`, `@`):
+/// `Compare 9ef6312813 ea63317630 master@origin`. A pair is one change
+/// however many lie between its points, its row after its last line `from..to
+/// N changes dates`. One set a pane: a later Changes or Compare replaces
+/// it. Bare: as bare Changes.
pub const Compare = struct {
pub const takes_arg = true;
pub const run = @import("jj.zig").compareWord;
};
-/// Count, for each declaration of a file's pane, the changes in `window` (jj) that touched it, and show it in this view: a heat lane after the line number and a strip by the scroll thumb, the line numbers' grey to the theme's red on a log scale; `window` a revset or a span of time (`3d`, `2w`, `6m`, `1y`); bare, shown here or not (none counted yet: the file's whole history).
+/// Show how many changes touched each declaration of this file, as a heat
+/// lane.
+///
+/// `Churn <window>`: a revset, or a span of time back from now (`3d`, `2w`,
+/// `6m`, `1y`). In this view a cell after the line number, from the line
+/// numbers' grey to the theme's red on a log scale, and a strip by the scroll
+/// thumb. Bare: hidden in this view or shown again; with none counted yet,
+/// the file's whole history.
pub const Churn = struct {
pub const takes_arg = true;
pub const run = @import("jj.zig").churnWord;
};
-/// Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text. `Diff <file>` stacks that diff's, `Diff <revision>` git show's.
-/// The diff viewer's one registration: its word and traits here, all else
-/// its own (hunks.zig).
+/// Show a diff's hunks stacked in a +Diff, each under its place, as a diff
+/// viewer shows them.
+///
+/// Bare, on a diff (a .diff, a .patch, a +Pager holding one): its hunks
+/// stacked; on a +Diff: the diff itself, as text. `Diff <file>`: that .diff's
+/// or .patch's hunks. `Diff <hash>` (7 to 40 hex digits): `git show` of that
+/// commit, in its own `+Diff-<hash>`. `Diff <change> [path[:line]]` (a jj
+/// change id): its patch, its header and whole message on top, the cursor at
+/// that place. `Diff <from>..<to> [path[:line]]`: the difference between two
+/// points, the changes between them on top.
+///
+/// Each hunk stands under its `path:line` and the declarations around it, a +
+/// or - before each line, the words a changed line changed tinted. `SPC j n`
+/// and `SPC j p` step through the hunks; B3 on a place opens it.
pub const Diff = struct {
+ // The diff viewer's one registration: its word and traits here, all else
+ // its own (hunks.zig).
pub const takes_arg = true;
pub const output: OutputTraits = .{ .name = config.diff_buffer, .steps = true, .locations = true };
pub const run = @import("hunks.zig").word;
@@ -1123,12 +1308,14 @@ pub const Togglettymode = struct {
}
};
-/// acme's Edit (exec.c `edit`, edit.c): sam's command language over the
-/// open text panes, from a tag, a pane ctl or exec, starting in the pane's
-/// body. One undo step in each file it changes; a failure changes nothing
-/// and says why. core/edit_cmd.zig runs it; core/sam_edit.zig has what is
-/// left out.
+/// Run a command of sam's language over the open text panes, starting in this
+/// pane's body.
+///
+/// As acme's Edit: from a tag, a pane's ctl or an exec. One undo step in each
+/// file it changes; a failure changes nothing and says why.
pub const Edit = struct {
+ // acme's Edit (exec.c `edit`, edit.c). core/edit_cmd.zig runs it;
+ // core/sam_edit.zig has what is left out.
pub const takes_arg = true;
pub const requires_arg = true;
pub fn run(c: Ctx) void {
@@ -1136,12 +1323,12 @@ pub const Edit = struct {
}
};
-/// acme's Undo and Redo (exec.c `undo`): step the pane's body back or
-/// forward through its edits, from a tag, a pane ctl or exec.
-/// With no step left, Undo and Redo say so and change nothing; a ctl write
-/// of them still succeeds, as acme's Undo is silent there. A file keeps
-/// limits.undo_max steps (256).
+/// Step the pane's text back one edit.
+///
+/// With no step left, it says so and changes nothing; a ctl write of it still
+/// succeeds, as acme's Undo is silent there. A file keeps 256 steps.
pub const Undo = struct {
+ // acme's Undo and Redo (exec.c `undo`); limits.undo_max steps.
pub fn run(c: Ctx) void {
if (@import("edit_cmd.zig").busyOn(c.p, c.id)) return c.p.reportFailure(c.id, "Undo: " ++ @import("edit_cmd.zig").e_busy);
if (c.pane.file) |f| if (f.history.journal.done == 0) return c.p.setMessage(.at(c.id), "Undo: nothing to undo");
@@ -1165,9 +1352,10 @@ pub const Collapse = struct {
}
};
-/// Undock a pane from the pane it answers for: it stays where it is, a
-/// pane of its own, and the next search from that pane opens another
-/// under it.
+/// Undock a pane from the pane it answers for: it stays where it is, a pane
+/// of its own.
+///
+/// The next search from that pane opens another under it.
pub const Undock = struct {
pub fn run(c: Ctx) void {
if (c.pane.docked_to == null) return c.p.reportFailure(c.id, "Undock: not docked to a pane");
@@ -1226,18 +1414,21 @@ pub const Term = struct {
}
};
-/// Binds this terminal as a language's REPL, so an exec on that language's
-/// files is typed into it instead of run. The language is named as the
-/// syntax table has it: an exec made on the body of a file in that
-/// language -- a middle click, the execute key, a single word like `ls`
-/// as much as a selection -- and one made on this terminal's own body, is
-/// typed into it (bracketed paste if its program asked for that, else line
-/// by line, then Enter) instead of run. `Repl python` binds (again, it is
-/// already); `Repl -` unbinds; `Repl` bare says what it is bound as. With
-/// several bound for a language, the exec asks which.
+/// Bind this terminal as a language's REPL: an exec on that language's files
+/// is typed into it.
+///
+/// The language is named as the syntax table has it (`py`, `Python`, `sh`).
+/// An exec made on the body of a file in that language (a middle click, the
+/// execute key, a single word like `ls` as much as a selection), and one made
+/// on this terminal's own body, is typed into it (bracketed paste if its
+/// program asked for that, else line by line, then Enter) instead of run.
+/// `Repl python` binds (again, it is already); `Repl -` unbinds; bare, it
+/// says what it is bound as. With several bound for a language, the exec asks
+/// which.
+///
/// Still commands, whatever is bound: a word in a tag, `Exec <text>` run by
-/// name (typed, a 2-1 chord onto Exec, a ctl line), and a command word
-/// @`cmd` in the text, looked at or clicked.
+/// name (typed, a 2-1 chord onto Exec, a ctl line), and a command word @`cmd`
+/// in the text, looked at or clicked.
pub const Repl = struct {
pub const takes_arg = true;
pub fn run(c: Ctx) void {
@@ -1338,8 +1529,10 @@ pub const Help = struct {
}
};
-/// Open the startup file, `init`, in a pane: its pane when it is open, else
-/// the file, else a pane of that name for Save to make it and its directory.
+/// Open the startup file, `init` in the configuration directory, in a pane.
+///
+/// Its pane when it is open, else the file; not there yet, a pane of that
+/// name, which Save makes, its directory too.
pub const Config = struct {
pub const scope: Scope = .session;
pub fn run(c: Ctx) void {
@@ -1425,10 +1618,12 @@ pub const Messages = struct {
}
};
-/// This build: its version, commit, jj change and build time (a stamped
-/// build's: a release or the ~/.local install), the zig that built it, its
-/// optimize mode, target, platform, grammars, whether the addons are compiled
-/// in, and its dependencies, printed into an output buffer.
+/// Show this build in a +Build: its version, compiler, optimize mode, target
+/// and dependencies.
+///
+/// A stamped build's (a release, or the ~/.local install) commit, jj change
+/// and build time too, its platform, its grammars, and whether the addons are
+/// compiled in.
pub const Build = struct {
pub const scope: Scope = .session;
pub const output: OutputTraits = .{ .name = config.build_buffer };
@@ -1437,8 +1632,7 @@ pub const Build = struct {
}
};
-/// This build's version and what changed to reach it, printed into an output
-/// buffer the same way Config prints the live settings.
+/// Show this build's version and what changed to reach it, in a +Changelog.
pub const Changelog = struct {
pub const scope: Scope = .session;
pub const output: OutputTraits = .{ .name = config.changelog_buffer };
@@ -1476,8 +1670,12 @@ pub const Find = struct {
}
};
-/// Find's sibling: Find matches file NAMES under this pane's directory, Grep
-/// matches the LINES of those files, on the disk engine's worker.
+/// List the lines of the files below this pane's directory that hold its
+/// argument.
+///
+/// Find matches the files' names, Grep the lines of those files, on the disk
+/// engine's worker. A query pane under this pane: bare (`SPC f g`) typed
+/// into; with a word, listed.
pub const Grep = struct {
pub const takes_arg = true;
pub const requires_arg = true;
@@ -1503,8 +1701,10 @@ fn search(c: Ctx, source: panes.Query.Source, miss: []const u8) void {
c.p.reportFailure(c.id, miss);
}
-/// Search in a query pane under this pane, line 1 the argument (`Panes`,
-/// `Symbols lay`, `All needle`, `/re`, any of its words); bare, `/`.
+/// Search in a query pane under this pane, its line 1 the argument.
+///
+/// Any of the query pane's words (`Search Panes`, `Search Symbols lay`,
+/// `Search All needle`, `Search /re`); bare, `/`.
pub const Search = struct {
pub const takes_arg = true;
pub const quiet = true;
@@ -1593,10 +1793,12 @@ pub const Right = struct {
}
};
-/// Emacs's follow-mode: one text across a chain of panes as consecutive
-/// pages, each going on where the one before ends, scrolled as one. Adds a
-/// page, a Zerox twin, at the end of the column right of the chain's last,
-/// or in a new column there; its tag has Unfollow.
+/// Show one text across a chain of panes as consecutive pages, scrolled as
+/// one.
+///
+/// As Emacs's follow-mode: each page goes on where the one before ends. Each
+/// Follow adds a page, a Zerox of the text, at the end of the column right of
+/// the chain's last, or in a new column there; its tag has Unfollow.
pub const Follow = struct {
pub fn run(c: Ctx) void {
if (@import("edit_cmd.zig").busyOn(c.p, c.id)) return c.p.reportFailure(c.id, "Follow: " ++ @import("edit_cmd.zig").e_busy);
@@ -1634,8 +1836,10 @@ pub const Follow = struct {
}
};
-/// Take this pane out of its Follow chain: it stays, a Zerox twin with the
-/// scroll it has, and the chain closes up behind it.
+/// Take this pane out of its Follow chain.
+///
+/// It stays, a Zerox twin with the scroll it has, and the chain closes up
+/// behind it.
pub const Unfollow = struct {
pub fn run(c: Ctx) void {
const f = if (c.pane.file) |*file| file else return c.p.reportFailure(c.id, "Unfollow: this pane is in no Follow chain");
@@ -1644,8 +1848,12 @@ pub const Unfollow = struct {
}
};
-/// Window mode: h/j/k/l move an outline between the panes; Enter or Esc
-/// focuses the outlined pane, `:` its tag, the letter shown on a pane that one; d is Del on it (then k or j between two), c Collapse.
+/// Window mode: move an outline between the panes and act on the one
+/// outlined.
+///
+/// h/j/k/l move the outline; Enter or Esc focuses the outlined pane, `:` its
+/// tag, the letter shown on a pane that one; d is Del on it (then k or j
+/// between two), c Collapse.
pub const Window = struct {
pub fn run(c: Ctx) void {
tagline.exitHeader(c.p);
@@ -1716,12 +1924,15 @@ pub const Recent = struct {
}
};
-/// List the state file's dumps, those Dump made and those every session's
-/// end left (dump.dumpExit), the newest first, each as the command that
-/// brings it back, `Restore <label>` on a line of its own, its date, size,
-/// pane count and the panes' names indented under it; a click on the
-/// Restore (an exec, or a look at the line) is that Restore.
+/// List the state file's dumps, newest first, each with the Restore that
+/// brings it back.
+///
+/// Those Dump made and those every session's end left: each a `Restore
+/// <label>` line, its date, size and pane count, the panes' names indented
+/// under it. A click on the Restore (an exec, or a Look at the line) is that
+/// Restore.
pub const History = struct {
+ // A session's end dumps it (dump.dumpExit).
pub const scope: Scope = .session;
pub const output: OutputTraits = .{ .name = config.history_buffer };
pub fn run(c: Ctx) void {
@@ -1744,8 +1955,10 @@ pub const Jumplist = struct {
// ---- the language group ----
-/// Go to the definition of the symbol under the cursor; with an argument
-/// (a 2-1 chord's selection), of that symbol, where it is nearest.
+/// Go to the definition of the symbol under the cursor.
+///
+/// With an argument (a 2-1 chord's selection), of that symbol, where it is
+/// nearest.
pub const Def = struct {
pub const takes_arg = true;
/// Its answer says what it found, a jump or a list or why not; its
@@ -1756,8 +1969,10 @@ pub const Def = struct {
}
};
-/// List the references to the symbol under the cursor; with an argument
-/// (a 2-1 chord's selection), to that symbol, where it is nearest.
+/// List the references to the symbol under the cursor.
+///
+/// With an argument (a 2-1 chord's selection), to that symbol, where it is
+/// nearest.
pub const Refs = struct {
pub const takes_arg = true;
pub const quiet = true; // as Def
@@ -1808,7 +2023,10 @@ pub const WsDiagnostics = struct {
}
};
-/// Run the file's language indexer at its project root, writing the index.scip the language words ask first.
+/// Run the file's language indexer at its project root, writing its
+/// index.scip.
+///
+/// The language words ask that index first.
pub const Index = struct {
pub fn run(c: Ctx) void {
c.p.lspRequest(c.id, .index, "");
@@ -1905,6 +2123,24 @@ fn testDump(buf: []u8) ![]const u8 {
return std.fmt.bufPrint(buf, "Restore {s}/d.zon", .{at});
}
+test "a builtin's documentation is the whole `///` block above it, a line a paragraph, its summary first" {
+ const Builtin = registry.Builtin();
+ const diff = registry.doc(Builtin.Diff);
+ try std.testing.expect(std.mem.startsWith(u8, diff.text, diff.summary));
+ try std.testing.expect(std.mem.endsWith(u8, diff.summary, "."));
+ // Its paragraphs, each its `///` lines joined: the forms in the second.
+ var paras = std.mem.splitScalar(u8, diff.text, '\n');
+ _ = paras.next();
+ try std.testing.expect(std.mem.indexOf(u8, paras.next().?, "`Diff <hash>` (7 to 40 hex digits)") != null);
+ try std.testing.expect(paras.next() != null);
+ // No note for the code's reader: those are `//` lines in the struct.
+ try std.testing.expect(std.mem.indexOf(u8, diff.text, "registration") == null);
+ // A setting's is its own doc.
+ try std.testing.expectEqualStrings(config.Settings.find("Wrap").?.doc, registry.doc(Builtin.Wrap).text);
+ // Every builtin has one, its summary a line (the compiler holds both).
+ for (std.enums.values(Builtin)) |b| try std.testing.expect(registry.doc(b).summary.len > 0);
+}
+
test "capabilities exactly gate setting builtins" {
const Builtin = registry.Builtin();
for (config.Settings.settings) |setting| {