summaryrefslogtreecommitdiff
path: root/src/builtins.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/builtins.zig')
-rw-r--r--src/builtins.zig49
1 files changed, 47 insertions, 2 deletions
diff --git a/src/builtins.zig b/src/builtins.zig
index 77e1169d..c1424b2f 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -46,6 +46,10 @@ pub const PaneKind = enum {
/// An image pane, or a terminal, whose program's kitty graphics are
/// pictures too.
picture,
+ /// A terminal, or a +Pager: a program's colours.
+ program_colors,
+ /// A text pane showing a diff: a .diff, a .patch, a +Pager holding one.
+ diff,
pub fn has(kind: PaneKind, pane: *const panes.Pane) bool {
return switch (kind) {
@@ -53,6 +57,9 @@ pub const PaneKind = enum {
.pdf => pane.hasPdf(),
.image => pane.image != null,
.picture => pane.image != null or pane.isTerminal(),
+ .program_colors => pane.isTerminal() or (pane.file != null and pane.file.?.pager),
+ .diff => if (pane.file) |f| pane.colorAlgo() == .diff or
+ (f.output != null and std.meta.eql(f.output.?.from, panes.Output.Origin{ .cmd = .Diff })) else false,
};
}
@@ -62,6 +69,8 @@ pub const PaneKind = enum {
.pdf => "a PDF",
.image => "an image",
.picture => "an image or a terminal",
+ .program_colors => "a terminal or a +Pager",
+ .diff => "a diff or a +Diff",
};
}
};
@@ -1336,14 +1345,28 @@ pub const Del = struct {
}
};
-/// Recolour a terminal'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, flipping between them.
pub const Filter = struct {
- pub const needs: PaneKind = .terminal;
+ pub const needs: PaneKind = .program_colors;
pub fn run(c: Ctx) void {
c.pane.tty_filter = !c.pane.tty_filter;
}
};
+/// 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.
+pub const Diff = struct {
+ pub const needs: PaneKind = .diff;
+ pub const output: OutputTraits = .{ .name = config.diff_buffer, .steps = true, .locations = true };
+ pub fn run(c: Ctx) void {
+ const f = &c.pane.file.?;
+ if (panes.Output.diffSource(c.p, f)) |source| return panes.Output.showDiffText(c.p, c.id, source);
+ _ = panes.Output.openDiff(c.p, c.id, f.path, f.content) catch |err| switch (err) {
+ error.NoHunks => c.p.reportFailure(c.id, "Diff: no hunk in it"),
+ else => c.p.reportError(c.id, "hunks", err),
+ };
+ }
+};
+
/// Cycle the pane's input modes: terminals add raw tty mode to normal/insert.
pub const Mode = struct {
pub fn run(c: Ctx) void {
@@ -1851,6 +1874,28 @@ 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.
+pub const Def = struct {
+ pub const takes_arg = true;
+ /// Its answer says what it found, a jump or a list or why not; its
+ /// name would only stack above it, as gd never did.
+ pub const quiet = true;
+ pub fn run(c: Ctx) void {
+ c.p.lspRequest(c.id, .definition, std.mem.trim(u8, c.arg orelse "", " \t\r\n"));
+ }
+};
+
+/// 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
+ pub fn run(c: Ctx) void {
+ c.p.lspRequest(c.id, .references, std.mem.trim(u8, c.arg orelse "", " \t\r\n"));
+ }
+};
+
/// Ask the language server about the symbol under the cursor.
pub const Hover = struct {
pub fn run(c: Ctx) void {