diff options
Diffstat (limited to 'src/builtins.zig')
| -rw-r--r-- | src/builtins.zig | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/src/builtins.zig b/src/builtins.zig index c8909e66..cda962de 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -1712,38 +1712,42 @@ const e_search_miss_grep = "Grep: text not found"; /// List the files below this pane's directory whose names hold its argument, in a +Search. pub const Find = struct { pub const takes_arg = true; + // A script's Find names what to find (bare, it is a key's prompt). pub const requires_arg = true; pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true }; pub fn run(c: Ctx) void { + // A query pane under this pane, line 1 `Find ` and the word: bare + // (SPC f f) typed into; with a word (B2, a script) listed, the + // keyboard left where it was, a script told of a miss. const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); - if (pat.len > 0) { - const rows = look.runSearch(c.p, c.id, pat, .find, .top, false) catch |err| return c.p.reportError(c.id, "Find", err); - if (rows == 0) c.p.reportFailure(c.id, e_search_miss_find); - return; - } - // Bare (SPC f f): the query pane, line 1 `Find `, typed into. - panes.Query.open(c.p, c.id, .find, "", true); + panes.Query.open(c.p, c.id, .find, pat, pat.len == 0); + if (pat.len > 0) missed(c, e_search_miss_find); } }; /// Find's sibling: Find matches file NAMES under this pane's directory, Grep -/// matches file CONTENTS under every pane's directory at once. +/// matches the LINES of those files, on the disk engine's worker. pub const Grep = struct { pub const takes_arg = true; pub const requires_arg = true; pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true, .locations = true }; pub fn run(c: Ctx) void { const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n"); - if (pat.len > 0) { - const rows = look.runSearch(c.p, c.id, pat, .grep, .top, false) catch |err| return c.p.reportError(c.id, "Grep", err); - if (rows == 0) c.p.reportFailure(c.id, e_search_miss_grep); - return; - } - // Bare (SPC f g): the query pane, line 1 `Grep `, typed into. - panes.Query.open(c.p, c.id, .grep, "", true); + panes.Query.open(c.p, c.id, .grep, pat, pat.len == 0); + if (pat.len > 0) missed(c, e_search_miss_grep); } }; +/// A script's Find or Grep (a 9P write runs it to its end before it +/// answers) that found nothing fails as one: the query pane stays, its +/// count 0, and the write hears `not found`. +fn missed(c: Ctx, text: []const u8) void { + if (!c.p.fs.serving) return; + const qid = panes.Query.ofOwner(c.p, c.pane.serial) orelse return; + const q = c.p.panes[qid].?.query.?; + if (q.total == 0) c.p.reportFailure(c.id, text); +} + /// Search in a query pane under this pane, line 1 the argument (`Panes`, /// `Symbols lay`, `All needle`, `/re`, any of its words); bare, `/`. pub const Search = struct { @@ -1898,11 +1902,10 @@ pub const Last = struct { pub const Recent = struct { pub const scope: Scope = .session; pub const takes_arg = true; - pub const output: OutputTraits = .{ .name = config.recent_buffer, .steps = true, .locations = true }; pub fn run(c: Ctx) void { - // From a pane: the query pane under it, line 1 `Recent `, typed - // into; from a header, which no pane owns, the +Recent list. - if (c.p.exec_header or c.p.panes[c.id] == null) return panes.Output.openRecent(c.p, c.id) catch |err| c.p.reportError(c.id, "recent", err); + // The query pane under the pane the keyboard is in, line 1 + // `Recent `, typed into; what follows the word narrows the files. + if (c.p.panes[c.id] == null) return c.p.reportFailure(c.id, "Recent: open a pane to search from"); panes.Query.open(c.p, c.id, .recent, std.mem.trim(u8, c.arg orelse "", " \t\r\n"), true); } }; |
