summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 21:45:46 -0300
committerGabriel Schneider <[email protected]>2026-11-26 23:24:00 -0300
commit24dc19130fd6a063bb7e86fa21a02d7af4c3b163 (patch)
tree761d6a1b439f5ea31f3679c8b4f2874e0acfbeb7
parent8d2a064eb69a1f888c435c3a0e03468b59abbb0d (diff)
downloadpardes-24dc19130fd6a063bb7e86fa21a02d7af4c3b163.tar.gz
pardes-24dc19130fd6a063bb7e86fa21a02d7af4c3b163.zip
Root, and the explicit root keys SPC f F, SPC f G and SPC :: Find, Grep and the `:` line run at the project's root, the nearest directory at or above the asking pane's holding a `.jj` or a `.git` (Pick.workTree, kept by zxsqtpol for this), the pane's own when none does, while SPC f f, SPC f g and `:` keep acme's directory (the user's ruling of 2026-11-26: "maybe some commands SHOULD run on the project root for convenience", explicit twins, nothing implicit); WHY A WORD: a leader leaf names a builtin (config.leader_path, leader_args) and `:` is a normal-mode role, so the three keys need one word that reaches the root: `Root <line>` runs the line as Exec does with the step's flag Pardes.exec_root set, bare (SPC :) it opens the `:` line marked to run there, and a script's `Root make` or `Root Grep x` falls out of it at a ctl for free; THE CHANGE: builtins.Root; Pardes.exec_root, a step's own (replica `.local`, root.zig's kept_out) like exec_column; execDir reads the root under it (a command pane's directory, Term's, and Query.create's, which now calls execDir in place of its copy of it); executeFrom sends Root's line to a command pane even from a shell at its prompt, and runCommand reuses only a finished command pane at the root for it (not the asking one); Pick.root: a picker Root asked lists from the root, its head `␣ f Find root`, `Grep root`, its list word `Find root …`, Exec on that word running at the root again, a Grep's leading directory read from the root (grepScope, unchanged); Command.root: SPC :'s line, its head `: root`, `= Root make` as its plain word, its Enter and its `:open ` run as Root; config: Root's leader path `:`, leader_args fF and fG run `Root Find` and `Root Grep`, which-key labels `Find root` and `Grep root` (bindings.zig); replica's may_wait gets back a kind row, `Root *` (the root's stat on the session's disk), walked as `Root Find` (walk_samples: bare Root, the `:` line, asks the disk nothing); docs: Root's own doc (the Help index row `SPC : Root`, builtins-tui.json from `zig build builtins-json`, the same line put in builtins-gui.json), the cheatsheet's leader list (three short rows), guide.typ's Find and Grep rows and its where-commands-run table; RUN (TEST FIRST): behaviour/find_grep.zig (the reference's Find and Grep chapter, new): a `.jj` project, `x.txt` two directories below it: SPC f f lists `x.txt` alone and no `Find root`, SPC f F `␣ f Find root` with `a/b/x.txt` and `top.txt` (`.jj` passed over); SPC f G `needle` `␣ f Grep root needle` with `a/b/x.txt:1 needle below` and `top.txt:1 … needle at the top`, `a needle` the first alone (a/ is the root's); look_and_exec.zig: `:pwd` makes a command pane named `<root>/a/b`, SPC : shows `: root` and its `pwd` a second command pane named `<root>` (a `.git` project), each body `% pwd`; the three fail on zxsqtpol 8d2a064eb69a (`not on the screen: ␣ f Find root`, `… ␣ f Grep root needle`, `… : root`), pass now; test/session.zig gains `advance`, the host's clock moved on, so a typed Grep's 80 ms pause comes due in a T1 test; REAL CHECK (a private detached session of this Debug build over 9P, CA's demo copied with a `.jj` at its top): from src/torque/types.cc SPC f f types.cc types.h, SPC f F `Find root` Makefile compile_commands.json src/torque/types.cc … 1/5, SPC f G ToString `Grep root` three hits from the root, `src ToString` narrowed, `:pwd` printed …/demo/src/torque, SPC : `: root`, `: root make = Root make`, its pwd printed …/demo, its make ran `clang++ … src/torque/types.cc` at the root (exit 2, the demo's error) and SPC e from types.cc walked to types.cc:7:11, `SPC :open Make` opened `Find root Make`; GOLDENS (process-test --update, read): leader.golden spc and unmapped (`: Root` after `/ All` in SPC's level), find.golden group (`F Find root`, `G Grep root` in SPC f's), nothing else moved; NO hot path (a stat per directory up to the root once per Root run; a flag and five bytes in the head); the dump and the digest gain two bools (Pick.root, Command.root): the 40,000-seed dump fuzz (40,000 + 40,000 join seeds, 1,779 image seeds) 11/11, core/fuzz.zig restored byte for byte; GATES: Debug core-test 1172/1349 (177 skipped), shell-test 1390/1393 (3 skipped; the walk with Root's row), addons 8/8, term-test 17/17, kitty-test 45/45, process-test 0 of 149 failed (3 skipped), pane-test 184/185, behaviour-test 293/293 and --replay 293/293 (+3), consumer-test, the soak twice (rtt 30/80/207: diverged 0, unequal 0, quiet checks 617/0 485/0 568/0 and 499/0 387/0 553/0, unlisted stops 0, the corpus 22 of 22 scenes the same, no leak), daemon.py plain x3, games, window-clients, clients x5, relink, launch, pair, gui, client-motion rc 0, far rc 1 (`no link of the far client ended under the flood`, as on the base), client-resize-real skipped (no compositor), the macOS x86_64 and arm64 and FreeBSD cross-builds; ReleaseSafe: the build (0 invalid options), the soak (diverged 0, unequal 0, quiet checks 514/0 381/0 543/0, unlisted stops 0), process-test 1 of 149 failed (root-ctl Restore, as on the base), upgrade from the installed ab9fa40a7bbb, upgrade-gui, upgrade-self (65 s) and upgrade-back (40 s) each nothing left behind, launch, clients x3, far, gui, client-motion, client-resize-real, client-idle, pair, plain x3 rc 0; load 1.2 to 3.6
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
-rw-r--r--core/Command.zig20
-rw-r--r--core/Core.zig10
-rw-r--r--core/Pick.zig17
-rw-r--r--core/Prompt.zig2
-rw-r--r--core/Query.zig2
-rw-r--r--core/bindings.zig3
-rw-r--r--core/builtins.zig19
-rw-r--r--core/config.zig8
-rw-r--r--core/exec.zig9
-rw-r--r--core/normal.zig2
-rw-r--r--core/replica.zig5
-rw-r--r--core/root.zig2
-rw-r--r--docs/typ/builtins-gui.json1
-rw-r--r--docs/typ/builtins-tui.json1
-rw-r--r--docs/typ/cheatsheet.typ3
-rw-r--r--docs/typ/guide.typ8
-rw-r--r--test/behaviour.zig1
-rw-r--r--test/behaviour/find_grep.zig63
-rw-r--r--test/behaviour/look_and_exec.zig21
-rw-r--r--test/session.zig8
-rw-r--r--test/snapshots/find.golden2
-rw-r--r--test/snapshots/leader.golden4
22 files changed, 184 insertions, 27 deletions
diff --git a/core/Command.zig b/core/Command.zig
index bb42bbbd..ce4dd132 100644
--- a/core/Command.zig
+++ b/core/Command.zig
@@ -19,7 +19,9 @@
//! pipes typed last. Enter runs the line as B2 runs a word: a command as
//! its pardes word (`:theme`'s the theme the window wears), anything else
//! Exec'd. `:` on the empty field gives the keyboard to the tag's own text,
-//! as `:` did before there was a field; `:` there gives it back.
+//! as `:` did before there was a field; `:` there gives it back. `SPC :`
+//! (Root bare) is its twin at the project's root: Enter runs the line as
+//! Root, head `: root`.
//!
//! A view's own, as its prompt is (TagState.prompt.command): which rows
//! the hits (TagState.hits) are of, and where in the field Tab writes.
@@ -69,6 +71,9 @@ from: u16 = 0,
/// Tab (or a click) wrote the current row into the field: the rows are
/// the line's from before it, which Tab steps on through.
completed: bool = false,
+/// `SPC :` (Root bare): the line runs at the project's root, its head
+/// `: root`.
+root: bool = false,
/// A command typed after `:`, its short name, what it takes, and what it
/// does: the pardes word it is.
@@ -97,10 +102,12 @@ const row_max = 96;
/// A doc's rows, the fewest the names' band has.
const doc_rows = 4;
-/// `:` in pane `pane`'s body: the field empty in its tag, every row.
-pub fn open(p: *Pardes, pane: *Pane) void {
+/// `:` in pane `pane`'s body: the field empty in its tag, every row; its
+/// line run by Root, at the project's root, when `root`.
+pub fn open(p: *Pardes, pane: *Pane, root: bool) void {
Prompt.open(p, pane, .command);
if (p.view().tag_state.kind != .prompt) return;
+ p.view().tag_state.prompt.command.root = root;
filter(p, pane);
}
@@ -166,8 +173,9 @@ pub fn filter(p: *Pardes, pane: *Pane) void {
var buf: [Field.max + 8]u8 = undefined;
const word = std.fmt.bufPrint(&buf, "Find {s}", .{arg}) catch return;
const id = TagState.hostOf(p) orelse return;
+ const root = c.root;
TagState.toRest(p);
- return exec.runBuiltin(p, config.exec_cmd, id, "", word);
+ return exec.runBuiltin(p, if (root) .Root else config.exec_cmd, id, "", word);
}
c.rows = typed[i].rows;
c.from = @intCast(l.name.len + 1);
@@ -508,13 +516,14 @@ fn run(p: *Pardes, id: usize, pane: *Pane) void {
// What it runs, read while the rows are there (the theme worn).
var buf: [Field.max + 16]u8 = undefined;
const r = plan(p, line, &buf);
+ const root = s.prompt.command.root;
TagState.toRest(p);
if (std.mem.trim(u8, line, " ").len == 0) return;
p.prompt_history.command.add(line);
p.registers.put(p.gpa, ':', line, 0, 1, true) catch |err| return p.reportError(.at(id), "command", err);
if (r.said) |why| return p.setMessage(.at(id), why);
switch (r.verb) {
- .exec => exec.runBuiltin(p, config.exec_cmd, id, "", r.word),
+ .exec => exec.runBuiltin(p, if (root) .Root else config.exec_cmd, id, "", r.word),
.look => exec.runBuiltin(p, config.look_cmd, id, "", r.word),
.pipe => {
const f = pane.file orelse return p.setMessage(.at(id), "only a file's text is piped");
@@ -537,6 +546,7 @@ pub fn plainWord(p: *Pardes, w: *std.Io.Writer, line: []const u8) ?[]const u8 {
.look => w.writeAll(r.word) catch return null,
.pipe => w.print("Edit |{s}", .{r.word}) catch return null,
}
+ if (r.verb == .exec and p.view().tag_state.prompt.command.root) return "Root";
return if (r.verb == .look) "Look" else "Exec";
}
diff --git a/core/Core.zig b/core/Core.zig
index 0b602ba2..84a58427 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -326,6 +326,9 @@ word_look: bool = false,
/// have no directory of their own: it runs in the session's
/// (`sessionDir`), as acme's row and column tags do.
exec_header: bool = false,
+/// The running word is Root's (`SPC :`, `SPC f F`, `SPC f G`): it runs at
+/// the project's root above its directory (execDir, Pick.open).
+exec_root: bool = false,
session_dir: [limits.host_path_cap]u8 = undefined,
/// A spawn's directory too long for the effect's inline buffer, by pane
/// slot: the effect then carries none, and perform gives the host this.
@@ -539,6 +542,7 @@ pub const replica = .{
// `init` makes them between any two steps.
"multi_first", "multi_stop", "multi_index",
"multi_count", "exec_depth", "exec_column",
+ "exec_root",
// How this process was started, and the last dump it made for
// its host to write: a session loaded elsewhere has its own.
"opts", "dump_out", "dump_export",
@@ -1902,10 +1906,10 @@ fn processDir(buf: *[limits.host_path_cap]u8) ?[]const u8 {
}
/// The directory a word run from pane `id`'s text or tag runs in, or,
-/// from a header, the session's.
+/// from a header, the session's; Root's, the project's root above it.
pub fn execDir(p: *Pardes, id: usize) []const u8 {
- if (p.exec_header) return p.sessionDir();
- return paneDir(p.panes[id] orelse return p.sessionDir());
+ const dir = if (p.exec_header or p.panes[id] == null) p.sessionDir() else paneDir(p.panes[id].?);
+ return if (p.exec_root) pardes.Pick.workTree(p, dir) else dir;
}
pub const SavePath = Effect.Buf(effect_path_cap);
diff --git a/core/Pick.zig b/core/Pick.zig
index 5499809a..09ecb521 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -94,6 +94,9 @@ word: Kind.Buf(24) = .{},
keys: Kind.Buf(4) = .{},
/// Where Find and Grep look; what the rows' paths are relative to.
dir: Kind.Buf(4096) = .{},
+/// Asked by Root (`SPC f F`, `SPC f G`): `dir` is the project's root above
+/// the asking pane's, and its head and list word say `root`.
+root: bool = false,
/// The pane that asked, under whose tag it hangs, and the one its Enter
/// lands in, whose body previews, by serial.
owner: u32 = 0,
@@ -255,7 +258,9 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: []
const pk = make(p, source) catch |err| return p.reportError(.at(from), "pick", err);
pk.word.set(if (word.len > 0) word else words.get(source).word);
pk.keys.set(words.get(source).keys);
- pk.dir.set(Pardes.paneDir(asker));
+ // Root's (`SPC f F`): from the project's root above the asking pane's.
+ pk.root = p.exec_root;
+ pk.dir.set(if (pk.root) workTree(p, Pardes.paneDir(asker)) else Pardes.paneDir(asker));
pk.rows = p.gpa.dupe(u8, rows) catch |err| return p.reportError(.at(from), "pick", err);
pk.cap = p.view().rects[from].h * 2 / 5;
hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "pick", err);
@@ -268,8 +273,8 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: []
/// The work tree `dir` is in: the nearest directory at or above it that
/// holds a `.jj` or a `.git` (a git worktree's is a file); `dir` itself
-/// when none does.
-fn workTree(p: *Pardes, dir: []const u8) []const u8 {
+/// when none does. Root's words run there (Pardes.execDir, `open`).
+pub fn workTree(p: *Pardes, dir: []const u8) []const u8 {
var d = dir;
while (true) {
var buf: [4096]u8 = undefined;
@@ -838,6 +843,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
// One Resume opened: where it stands among the kept (UX L'2).
if (p.resume_at != 0) try text.print(arena, "Resume {d}/{d} ", .{ p.resume_at, nkept(p) });
try text.appendSlice(arena, pk.word.slice());
+ if (pk.root) try text.appendSlice(arena, " root");
try text.append(arena, ' ');
for (pk.refined[0..pk.nrefined]) |r| try text.print(arena, "{s} | ", .{r.query.slice()});
if (pk.spine == .edit) try text.print(arena, "{s} | Edit ", .{pk.query.slice()});
@@ -1784,6 +1790,7 @@ fn land(p: *Pardes, wanted: How) void {
fn wordOf(p: *const Pardes, pk: *const Pick, buf: *Kind.Buf(Trail.max_text)) []const u8 {
var w: std.Io.Writer = .fixed(&buf.bytes);
w.writeAll(pk.word.slice()) catch {};
+ if (pk.root) w.writeAll(" root") catch {};
for (pk.refined[0..pk.nrefined]) |r| w.print(" {s} |", .{r.query.slice()}) catch {};
if (pk.query.len > 0) w.print(" {s}", .{pk.query.slice()}) catch {};
const n = count(p, pk);
@@ -1889,6 +1896,10 @@ pub fn rerun(p: *Pardes, id: usize, index: u32) void {
const pk = byId(p, index) orelse return p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept");
var query: Kind.Buf(256) = .{};
query.set(pk.query.slice());
+ // One Root asked runs at the root again.
+ const was = p.exec_root;
+ p.exec_root = was or pk.root;
+ defer p.exec_root = was;
open(p, id, pk.source, pk.word.slice(), query.slice(), pk.rows);
}
diff --git a/core/Prompt.zig b/core/Prompt.zig
index d5f9a374..0b74ee68 100644
--- a/core/Prompt.zig
+++ b/core/Prompt.zig
@@ -1109,6 +1109,8 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head {
const text = &b.text;
const spans = &b.spans;
try styled(arena, text, spans, info.get(pr.op).cell, .key);
+ // `SPC :`'s line runs at the project's root (Root): its scope named.
+ if (pr.op == .command and pr.command.root) try text.appendSlice(arena, " root");
try text.append(arena, ' ');
const caret: u32 = @intCast(text.items.len + s.field.caret);
const line = s.field.text();
diff --git a/core/Query.zig b/core/Query.zig
index 96047ca1..d2c663ed 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -289,7 +289,7 @@ fn create(p: *Pardes, owner_id: usize, line: []const u8, source: Source) ?usize
p.reportError(.at(owner_id), "search", error.NoPaneSlots);
return null;
};
- const dir = if (p.exec_header) p.sessionDir() else Pardes.paneDir(owner);
+ const dir = p.execDir(owner_id);
const content = std.mem.concat(p.gpa, u8, &.{ line, "\n" }) catch return null;
const np = Output.open(p, free, dir, .search, "", content) catch |err| {
p.gpa.free(content);
diff --git a/core/bindings.zig b/core/bindings.zig
index 6128e311..e59f0f4a 100644
--- a/core/bindings.zig
+++ b/core/bindings.zig
@@ -149,7 +149,8 @@ fn leaderLevel(comptime prefix: []const u8) []const Node {
const path = config.leader_path.get(b) orelse continue;
if (std.mem.eql(u8, path, here)) break .{ .key = k, .label = @tagName(b), .leaf = .{ .builtin = b }, .lsp = lsp };
} else for (config.leader_args, 0..) |la, a| {
- if (std.mem.eql(u8, la.path, here)) break .{ .key = k, .label = la.arg, .leaf = .{ .arg = a }, .lsp = lsp };
+ // Root's twins say their scope, as their heads do: `Find root`.
+ if (std.mem.eql(u8, la.path, here)) break .{ .key = k, .label = if (la.cmd == .Root) la.arg ++ " root" else la.arg, .leaf = .{ .arg = a }, .lsp = lsp };
} else .{ .key = k, .label = groupLabel(here), .children = leaderLevel(here), .group = groupIndex(here) };
}
return sorted(&nodes);
diff --git a/core/builtins.zig b/core/builtins.zig
index 62e53eaf..e5421cd4 100644
--- a/core/builtins.zig
+++ b/core/builtins.zig
@@ -414,6 +414,25 @@ pub const Exec = struct {
}
};
+/// Run its argument as Exec does, at the project's root.
+///
+/// The root is the nearest directory at or above this pane's holding a
+/// `.jj` or a `.git`, else this pane's own. `Root make` runs make there in a
+/// command pane; `Root Find` and `Root Grep` (`SPC f F`, `SPC f G`) search
+/// from there, their heads `Find root` and `Grep root`, a Grep's leading
+/// directory read from the root. Bare (`SPC :`), the `:` line, its head
+/// `: root`, whose Enter runs the line there.
+pub const Root = struct {
+ pub const takes_arg = true;
+ pub fn run(c: Ctx) void {
+ const line = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
+ if (line.len == 0) return @import("Command.zig").open(c.p, c.pane, true);
+ c.p.exec_root = true;
+ defer c.p.exec_root = false;
+ _ = exec.executeFrom(c.p, c.id, line, c.from_body);
+ }
+};
+
// ---- session ----
/// Which panes a refusal asks about: every one (Exit, Restore), one (Del),
diff --git a/core/config.zig b/core/config.zig
index d500cdcb..69636d1d 100644
--- a/core/config.zig
+++ b/core/config.zig
@@ -28,11 +28,15 @@ const undecided: []const u8 = "<undecided>";
/// Leader paths that run a builtin WITH an argument (the pick prototype's):
/// the query pane's sources that have no word of their own, `Search` and
/// line 1. `SPC s` is the session group (Dump, Restore, Attach), so the
-/// declarations are `SPC s s`, a key from helix's.
+/// declarations are `SPC s s`, a key from helix's. Find's and Grep's twins
+/// at the project's root (Root, the user's explicit root keys) are their
+/// keys' capitals.
pub const leader_args = [_]struct { path: []const u8, cmd: Builtin, arg: []const u8 }{
.{ .path = "bb", .cmd = .Search, .arg = "Panes" },
.{ .path = "ss", .cmd = .Search, .arg = "Symbols" },
.{ .path = "/", .cmd = .Search, .arg = "All" },
+ .{ .path = "fF", .cmd = .Root, .arg = "Find" },
+ .{ .path = "fG", .cmd = .Root, .arg = "Grep" },
};
comptime {
@@ -155,6 +159,8 @@ pub const leader_path = paths: {
.Look = null,
.Mini = null,
.Exec = null,
+ // `:`'s twin, its line run at the project's root.
+ .Root = ":",
});
if (builtins.capabilities.font_picker) {
table.set(.Fonts, "tf");
diff --git a/core/exec.zig b/core/exec.zig
index 611e3430..fd2c6b1c 100644
--- a/core/exec.zig
+++ b/core/exec.zig
@@ -695,8 +695,8 @@ pub fn executeFrom(p: *Pardes, id: usize, txt: []const u8, from_body: bool) ?usi
}
// A command from a column's or the workspace's tag is that tag's: a
// command pane in the session's directory, never typed into whichever
- // terminal has the keyboard.
- if (p.exec_header or !takesCommandLine(p, id)) return runCommand(p, id, cmd);
+ // terminal has the keyboard; Root's, one at the project's root.
+ if (p.exec_header or p.exec_root or !takesCommandLine(p, id)) return runCommand(p, id, cmd);
// At a prompt with typed text below it: the output area padded with
// newlines so the command's output does not overwrite the buffer.
if (pane.ovl) |o| if (pane.isTerminal()) if (pane.terminal) |state| if (panes.Term.prompt(state).at_prompt) {
@@ -741,11 +741,12 @@ pub fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize {
// Not one whose pty a job it left behind still prints to: reusing it
// would hang that job up.
// From a column's tag, only a finished pane in that column is reused,
- // as the new one goes in that column (layout.placeNew).
+ // as the new one goes in that column (layout.placeNew); Root's line,
+ // only one at the root.
// Nor one leased: an open that was answered its serial and is still
// open reads that pane's output, which another client's command must
// not replace; a new pane runs it instead.
- const reuse: ?usize = if (!p.exec_header and p.exec_column == null and src != null and src.?.command != null and src.?.command_done and !src.?.command_pty and !leased(p, src.?.serial)) from else for (p.panes, 0..) |slot, i| {
+ const reuse: ?usize = if (!p.exec_header and !p.exec_root and p.exec_column == null and src != null and src.?.command != null and src.?.command_done and !src.?.command_pty and !leased(p, src.?.serial)) from else for (p.panes, 0..) |slot, i| {
const other = slot orelse continue;
if (p.exec_column) |c| if (if (layout.findPane(p, i)) |f| f.col != c else true) continue;
if (other.command != null and other.command_done and !other.command_pty and std.mem.eql(u8, other.cwdSlice(), dir) and !leased(p, other.serial)) break i;
diff --git a/core/normal.zig b/core/normal.zig
index e6d6dbb0..813b553a 100644
--- a/core/normal.zig
+++ b/core/normal.zig
@@ -1398,7 +1398,7 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error!
.command_line => switch (t.what) {
.tag => pane.focus = .body,
.column, .workspace => tagline.exitHeader(p),
- .body => Command.open(p, pane),
+ .body => Command.open(p, pane, false),
.input => tagline.enterTag(p, pane),
},
inline .pipe_selection, .pipe_selection_to, .insert_output, .append_output, .keep_pipe => |role| {
diff --git a/core/replica.zig b/core/replica.zig
index 172ab6f3..546ed679 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -7352,6 +7352,7 @@ const may_wait = [_]Wait{
.{ .what = "Save", .on = .any, .stop = "write_file", .why = "a save" },
// A program run, a shell opened or closed: the session's processes.
.{ .what = "Exec *", .on = .any, .stop = "kind", .why = "a program run: its name asked of the disk first" },
+ .{ .what = "Root *", .on = .any, .stop = "kind", .why = "the project's root, a `.jj` or `.git` at or above the pane's directory asked of the session's disk (Pick.workTree), as Find's listing and a program run are the session's (SPC f F, SPC f G, SPC :'s line)" },
.{ .what = "Exec *", .on = .any, .stop = "tty_taken", .why = "a program run in a shell: whether one has it, the session's" },
.{ .what = "Exec *", .on = .command, .stop = "run a command", .why = "a line run again in its directory's finished command pane: its process and its emulator are the session's" },
.{ .what = "Term", .on = .any, .stop = "kind", .why = "a shell opened: its name asked of the disk first" },
@@ -7441,13 +7442,15 @@ const walk_prefixes = prefixes: {
break :prefixes ks;
};
-/// The argument a word that means nothing without one is walked with.
+/// The argument a word that means nothing without one is walked with, and
+/// Root's, whose bare `:` line asks the disk nothing.
const walk_samples = [_]struct { []const u8, []const u8 }{
.{ "Look", "mise.toml" }, .{ "Exec", "echo" }, .{ "Mount", "x" }, .{ "Unmount", "x" },
.{ "Msg", "hi" }, .{ "ThemeFile", "t.zon" }, .{ "Edit", "s/a/b/" }, .{ "Mini", "x" },
.{ "Find", "x" }, .{ "Grep", "x" }, .{ "Rename", "x" }, .{ "WsSymbols", "x" },
.{ "Theme", "acme" }, .{ "Font", "Mono 12" }, .{ "TaglineSize", "100" }, .{ "WindowOpacity", "100" },
.{ "MessageLinger", "1000" }, .{ "InactiveDim", "0" }, .{ "GripWidth", "100" }, .{ "At", "@-" },
+ .{ "Root", "Find" },
};
fn keyName(buf: []u8, k: pardes.Key) []const u8 {
diff --git a/core/root.zig b/core/root.zig
index 14f9fede..98445d38 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -789,7 +789,7 @@ const kept_out = [_]struct { []const u8, []const u8, []const u8 }{
.{ "Core.zig", "diff_output locations_cache tty_filter_palette", "caches of pure functions of their key (a text, a theme): a step finds what it would make; a query row's colours from them are out of its digest (locations.Row.digest), and what a step asks a worker to paint is never decided by them (Stream.paintRows)" },
.{ "Core.zig", "retired_panes", "panes torn down this step, freed at its end" },
.{ "Core.zig", "theme_preview preview_chrome", "a themes picker's preview (colors.previewTheme): made from the live picker's cursor, in the digest with it, after every step (Pick.produceAll) and gone at its roll-up; a step reading a theme meanwhile reads the one its own state previews" },
- .{ "Core.zig", "multi_first multi_stop multi_index multi_count exec_depth exec_column", "a step's own: set by a key's replay across the ranges (normal.replaySels) and a word's run (exec.zig), each put back before the step ends; between steps what `init` makes, so a load takes them as it makes them (a dump's said 2^30 ranges once: a yank sized its register by it)" },
+ .{ "Core.zig", "multi_first multi_stop multi_index multi_count exec_depth exec_column exec_root", "a step's own: set by a key's replay across the ranges (normal.replaySels) and a word's run (exec.zig), each put back before the step ends; between steps what `init` makes, so a load takes them as it makes them (a dump's said 2^30 ranges once: a yank sized its register by it)" },
.{ "Core.zig", "rects col_x col_w", "a view's geometry: the layout pass's (layout.compute) over its columns and screen, at every sync and resize, and at a load (dump.afterLoad); never read before it" },
.{ "Core.zig", "distrusted frames tape", "Options: the client's own list, its runner's statistics, its tape" },
.{ "Event.zig", "native_image_patches", "what this process's shell can take" },
diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json
index ee7375c8..d846c2b7 100644
--- a/docs/typ/builtins-gui.json
+++ b/docs/typ/builtins-gui.json
@@ -95,6 +95,7 @@
{"name": "Restore", "leader": "SPC s r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Replace every pane with those of a dump.", "text": "Replace every pane with those of a dump.\n`Restore <label>`: the state file's dump of that label (History lists them); `Restore <file>`: a dump file's, a path, or the name of a file in the DumpDir or the directory pardes runs in. Bare: the last one this session made, else the newest. A file that is not a dump is said first; then, as Exit, it is refused once while a pane holds unsaved text."},
{"name": "Resume", "leader": "SPC '", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Reopen the last picker as it was: its rows, marks, cursor and query.", "text": "Reopen the last picker as it was: its rows, marks, cursor and query.\nUnder this pane's tag, previewing where its Enter lands: this pane if it reads, else its reader. `SPC '`; again after its Esc, nothing typed between, the one before it; Ctrl-o and Ctrl-i in it, the older and newer."},
{"name": "Right", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane, or column tag, to the right.", "text": "Move the keyboard to the pane, or column tag, to the right."},
+ {"name": "Root", "leader": "SPC :", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Run its argument as Exec does, at the project's root.", "text": "Run its argument as Exec does, at the project's root.\nThe root is the nearest directory at or above this pane's holding a `.jj` or a `.git`, else this pane's own. `Root make` runs make there in a command pane; `Root Find` and `Root Grep` (`SPC f F`, `SPC f G`) search from there, their heads `Find root` and `Grep root`, a Grep's leading directory read from the root. Bare (`SPC :`), the `:` line, its head `: root`, whose Enter runs the line there."},
{"name": "Save", "leader": "SPC f s", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Write the pane's text to its file, or to the file its argument names.", "text": "Write the pane's text to its file, or to the file its argument names.\n`Save <path>` writes it there. Bare, a pane with no file of its own (a +New, a list, a terminal) asks for a path; a file at a revision is read-only, written only to a path. Over a file changed on disk since it was read, it warns once."},
{"name": "Search", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Search in a query pane under this pane, its line 1 the argument.", "text": "Search in a query pane under this pane, its line 1 the argument.\nLine 1's first word names what it searches: `/re` this pane's text, `Find`, `Grep`, `Recent`, `Panes`, `Symbols`, `All` (every open pane's text), `Refs`, `Def`, `Impl`, `Diagnostics`; a line with none of them is a `/`: `Search lay` is `/lay`. Bare, `/`, typed into. `SPC b b`, `SPC s s` and `SPC /` open it with Panes, Symbols and All."},
{"name": "SelectRefs", "leader": "SPC l h", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Select every reference to the symbol under the cursor.", "text": "Select every reference to the symbol under the cursor."},
diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json
index 99e46ac7..57ac63f3 100644
--- a/docs/typ/builtins-tui.json
+++ b/docs/typ/builtins-tui.json
@@ -90,6 +90,7 @@
{"name": "Restore", "leader": "SPC s r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Replace every pane with those of a dump.", "text": "Replace every pane with those of a dump.\n`Restore <label>`: the state file's dump of that label (History lists them); `Restore <file>`: a dump file's, a path, or the name of a file in the DumpDir or the directory pardes runs in. Bare: the last one this session made, else the newest. A file that is not a dump is said first; then, as Exit, it is refused once while a pane holds unsaved text."},
{"name": "Resume", "leader": "SPC '", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Reopen the last picker as it was: its rows, marks, cursor and query.", "text": "Reopen the last picker as it was: its rows, marks, cursor and query.\nUnder this pane's tag, previewing where its Enter lands: this pane if it reads, else its reader. `SPC '`; again after its Esc, nothing typed between, the one before it; Ctrl-o and Ctrl-i in it, the older and newer."},
{"name": "Right", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane, or column tag, to the right.", "text": "Move the keyboard to the pane, or column tag, to the right."},
+ {"name": "Root", "leader": "SPC :", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Run its argument as Exec does, at the project's root.", "text": "Run its argument as Exec does, at the project's root.\nThe root is the nearest directory at or above this pane's holding a `.jj` or a `.git`, else this pane's own. `Root make` runs make there in a command pane; `Root Find` and `Root Grep` (`SPC f F`, `SPC f G`) search from there, their heads `Find root` and `Grep root`, a Grep's leading directory read from the root. Bare (`SPC :`), the `:` line, its head `: root`, whose Enter runs the line there."},
{"name": "Save", "leader": "SPC f s", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Write the pane's text to its file, or to the file its argument names.", "text": "Write the pane's text to its file, or to the file its argument names.\n`Save <path>` writes it there. Bare, a pane with no file of its own (a +New, a list, a terminal) asks for a path; a file at a revision is read-only, written only to a path. Over a file changed on disk since it was read, it warns once."},
{"name": "Search", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Search in a query pane under this pane, its line 1 the argument.", "text": "Search in a query pane under this pane, its line 1 the argument.\nLine 1's first word names what it searches: `/re` this pane's text, `Find`, `Grep`, `Recent`, `Panes`, `Symbols`, `All` (every open pane's text), `Refs`, `Def`, `Impl`, `Diagnostics`; a line with none of them is a `/`: `Search lay` is `/lay`. Bare, `/`, typed into. `SPC b b`, `SPC s s` and `SPC /` open it with Panes, Symbols and All."},
{"name": "SelectRefs", "leader": "SPC l h", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Select every reference to the symbol under the cursor.", "text": "Select every reference to the symbol under the cursor."},
diff --git a/docs/typ/cheatsheet.typ b/docs/typ/cheatsheet.typ
index 2307db2c..dfc9f71c 100644
--- a/docs/typ/cheatsheet.typ
+++ b/docs/typ/cheatsheet.typ
@@ -88,6 +88,9 @@ Helix-style: motions *select*, then an edit acts on the selection. Mode box: bla
key("SPC f n"), word("New"),
key("SPC f f"), word("Find"),
key("SPC f g"), word("Grep"),
+ key("SPC f F"), [#word("Find") at the root],
+ key("SPC f G"), [#word("Grep") at the root],
+ key("SPC :"), [`:` at the root],
key("SPC f r"), word("Recent"),
key("SPC f h"), word("History"),
key("SPC f l"), [#word("Lists"): the kept pickers],
diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ
index 6d14c97c..df78852b 100644
--- a/docs/typ/guide.typ
+++ b/docs/typ/guide.typ
@@ -135,10 +135,12 @@ Where it runs depends on where you clicked:
[any other pane's text or tag], [a command pane in that pane's directory, in the last column],
[a column's tag], [a command pane in the session's directory, in that column],
[the workspace tag], [a command pane in the session's directory, in the last column],
+ [#key("SPC :") (#word("Root"))], [a command pane at the project's root: the nearest directory at or above the pane's holding a `.jj` or `.git`],
)
A file's text and tag run in its directory: `make` from `README` at the
-project root is right, from `src/main.c` it is not. The keyboard stays
+project root is right, from `src/main.c` it is not; #key("SPC :") `make`
+runs it at the root from anywhere in the project. The keyboard stays
where it was. The command pane's tag ends in `running`, then `exit N`:
#tag("Del", path: "/home/me/src (make) exit 0")
@@ -208,8 +210,8 @@ Line 1's first word names what it searches, and editing the word changes it:
#pairs(
[`/pat`], [the pane's own text: a regex, any case unless it has a capital (#key("/"))],
- [`Find name`], [the files below the pane's directory, by a fuzzy match of their names (#key("SPC f f"), #word("Find"))],
- [`Grep text`], [the lines of those files holding `text`, literally (#key("SPC f g"), #word("Grep")); past 2000 lines #word("More") goes on],
+ [`Find name`], [the files below the pane's directory, by a fuzzy match of their names (#key("SPC f f"), #word("Find")); #key("SPC f F") from the project's root, the nearest directory above holding a `.jj` or `.git`],
+ [`Grep text`], [the lines of those files holding `text`, literally (#key("SPC f g"), #word("Grep"); #key("SPC f G") from the project's root); past 2000 lines #word("More") goes on],
[`Recent name`], [the files opened lately, in any window (#key("SPC f r"), #word("Recent"))],
[`Panes name`], [the open panes, then the ones closed this session, `(closed)` and dimmer: #key("Enter") (or a #word("Look") at its `@pN`) brings one back where it was, its text with it (#key("SPC b b"), #word("Panes"))],
[`Symbols name`], [the text's symbols, a row each: its kind's mark (`t` type, `f` function, `m` field, `c` const, `v` var, `n` module, `·` other), its name in the ones it is in (`Counts.lines`), what its line says after the name; types, functions, fields, then the rest, each in the text's order, and so while typed, the best match current (#key("SPC s s"))],
diff --git a/test/behaviour.zig b/test/behaviour.zig
index 9fe1f50b..3822988e 100644
--- a/test/behaviour.zig
+++ b/test/behaviour.zig
@@ -11,6 +11,7 @@ test {
_ = @import("behaviour/columns_and_tags.zig");
_ = @import("behaviour/edit.zig");
_ = @import("behaviour/event.zig");
+ _ = @import("behaviour/find_grep.zig");
_ = @import("behaviour/flags.zig");
_ = @import("behaviour/follow.zig");
_ = @import("behaviour/from_acme.zig");
diff --git a/test/behaviour/find_grep.zig b/test/behaviour/find_grep.zig
new file mode 100644
index 00000000..49bf64aa
--- /dev/null
+++ b/test/behaviour/find_grep.zig
@@ -0,0 +1,63 @@
+//! docs/typ/reference.typ, Find and Grep <find-grep>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+fn has(haystack: []const u8, needle: []const u8) bool {
+ return std.mem.indexOf(u8, haystack, needle) != null;
+}
+
+/// A project in `tmp`: a `.jj` at its top, `top.txt` there and `x.txt`
+/// two directories below, in `a/b`, each holding `needle`; its path.
+fn project(s: *Session, tmp: *std.testing.TmpDir) ![]const u8 {
+ try tmp.dir.createDirPath(std.testing.io, ".jj");
+ try tmp.dir.createDirPath(std.testing.io, "a/b");
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "top.txt", .data = "needle at the top\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a/b/x.txt", .data = "needle below\n" });
+ var buf: [4096]u8 = undefined;
+ return s.arena.allocator().dupe(u8, buf[0..try tmp.dir.realPath(std.testing.io, &buf)]);
+}
+
+test "find-grep: SPC f f lists the files of the pane's directory, SPC f F those of the project's root above it, its head `Find root`" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const root = try project(&s, &tmp);
+ _ = try s.lookFile(s.at("{s}/a/b/x.txt", .{root}));
+ try s.keys(" ff");
+ s.tick();
+ _ = try s.where("▶ x.txt");
+ try std.testing.expect(!has(try s.screen(), "top.txt"));
+ try std.testing.expect(!has(try s.screen(), "Find root"));
+ try s.keys("\x1b");
+ // From the root: its files by their paths from it, `.jj` passed over.
+ try s.keys(" fF");
+ s.tick();
+ _ = try s.where("␣ f Find root");
+ _ = try s.where(" a/b/x.txt");
+ _ = try s.where(" top.txt");
+ try std.testing.expect(!has(try s.screen(), ".jj"));
+}
+
+test "find-grep: SPC f G greps from the project's root above the pane's directory, its head `Grep root`, a leading directory narrowing it from the root" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const root = try project(&s, &tmp);
+ _ = try s.lookFile(s.at("{s}/a/b/x.txt", .{root}));
+ try s.keys(" fGneedle");
+ s.advance(100 * std.time.ns_per_ms);
+ s.tick();
+ _ = try s.where("␣ f Grep root needle");
+ // Each row its place from the root, the places' column padded.
+ _ = try s.where("a/b/x.txt:1 needle below");
+ _ = try s.where("top.txt:1 needle at the top");
+ try s.keys("\x1b");
+ // `a needle`: the root's a/, which the pane's directory has not.
+ try s.keys(" fGa needle");
+ s.advance(100 * std.time.ns_per_ms);
+ s.tick();
+ _ = try s.where("a/b/x.txt:1 needle below");
+ try std.testing.expect(!has(try s.screen(), "top.txt:1"));
+}
diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig
index 3e6137b1..387c28a7 100644
--- a/test/behaviour/look_and_exec.zig
+++ b/test/behaviour/look_and_exec.zig
@@ -442,6 +442,27 @@ fn tmpPath(s: *Session, tmp: *std.testing.TmpDir) ![]const u8 {
return s.at("{s}", .{buf[0..try tmp.dir.realPath(std.testing.io, &buf)]});
}
+test "look-and-exec: SPC : runs its line in a command pane at the project's root, the nearest directory at or above the pane's holding a .jj or a .git, where `:` runs it in the pane's own; its head `: root`" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.createDirPath(std.testing.io, ".git");
+ try tmp.dir.createDirPath(std.testing.io, "a/b");
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a/b/x.txt", .data = "x\n" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const root = try tmpPath(&s, &tmp);
+ _ = try s.lookFile(s.at("{s}/a/b/x.txt", .{root}));
+ try s.keys(":pwd\n");
+ const here = try paneNamed(&s, s.at("{s}/a/b", .{root}));
+ try std.testing.expect(std.mem.startsWith(u8, try s.read(s.at("/pane/{d}/body", .{here})), "% pwd\n"));
+ try s.keys(" :");
+ _ = try s.where(": root");
+ try s.keys("pwd\n");
+ const at_root = try paneNamed(&s, root);
+ try std.testing.expect(at_root != here);
+ try std.testing.expect(std.mem.startsWith(u8, try s.read(s.at("/pane/{d}/body", .{at_root})), "% pwd\n"));
+}
+
test "look-and-exec: a look opens spaced paths and locations without editing the source pane" {
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
diff --git a/test/session.zig b/test/session.zig
index 91cca3e5..e82c8bee 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -340,6 +340,14 @@ pub const Session = struct {
s.drain();
}
+ /// The host's clock on by `ns`, as its loop moves it: what waits on
+ /// time (a typed Grep's pause) is due at the next tick.
+ pub fn advance(s: *Session, ns: u64) void {
+ const p = pardesOf(s);
+ p.advance(p.clock.now_ns + ns);
+ s.drain();
+ }
+
/// Kinds' jobs and draws held from now on (`hold_jobs`), until
/// `releaseJobs`.
pub fn holdJobs(s: *Session) void {
diff --git a/test/snapshots/find.golden b/test/snapshots/find.golden
index 493f9e11..ac1e433d 100644
--- a/test/snapshots/find.golden
+++ b/test/snapshots/find.golden
@@ -1,7 +1,7 @@
== snap group grid=120x41 cursor=hidden
| New Term Find Grep Newcol Help Exit
| /tmp/pardes-snap/find/cwd/here.txt Keep Del
-| ␣ f ▸ c Config f Find g Grep h History l Lists n New r Recent s Save ? help
+| ␣ f ▸ c Config f Find F Find root g Grep G Grep root h History l Lists n New r Recent s Save ? help
|
|
|
diff --git a/test/snapshots/leader.golden b/test/snapshots/leader.golden
index 29f86d82..cffccfa6 100644
--- a/test/snapshots/leader.golden
+++ b/test/snapshots/leader.golden
@@ -2,7 +2,7 @@
| New Term Find Grep Newcol Help Exit
| /tmp/pardes-snap/leader/cwd/cmds.txt Keep Del
| ␣ ▸ b buffer… c column… f file… h help… j jump… l lsp… n new… s session… t view… ' Resume
-| │ / All ? Help d Del e Message p ClipPaste P ClipPasteBefore q Exit R ClipReplace
+| │ / All : Root ? Help d Del e Message p ClipPaste P ClipPasteBefore q Exit R ClipReplace
| │ w Window y ClipYank Y ClipYankMain ? help
|
|
@@ -48,7 +48,7 @@
|2: 1 Help Help h Help t Help c Help l
== snap unmapped grid=100x41 cursor=hidden
|2: ␣ ▸ b buffer… c column… f file… h help… j jump… l lsp… n new… s session… t view… ' Resume
-|3: │ / All ? Help d Del e Message p ClipPaste P ClipPasteBefore q Exit R ClipReplace
+|3: │ / All : Root ? Help d Del e Message p ClipPaste P ClipPasteBefore q Exit R ClipReplace
|4: │ w Window y ClipYank Y ClipYankMain x ? help
== snap help-group grid=100x41 cursor=7,5
|2: 1 Help Help h Help t Help c Help l