Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Luau API

What plugins and your config get from require("@greed"): the module first, then the types it hands out. Positions are 0-based byte offsets and lines are 0-based, as language servers count them.

Greed

command

command: (spec: CommandSpec) -> ()

cli

cli: (spec: CliSpec) -> ()

Adds a command line command, greed NAME ARGS; see CliSpec.

run

run: (name: string, opts: { args: { string }?, force: boolean?, count: number?, wait: boolean? }?) -> ()

Runs a command by name, optionally with arguments, force and a count. It returns once the command waits for something (a key, a prompt, a reply); with wait, a command or handler instead waits until it has finished, without blocking the editor. The command can do only what this plugin may too, unless it has “commands”.

eval

eval: (source: string, opts: { sandbox: boolean? }?) -> (boolean, string)

Runs Luau code in a scratch environment whose globals persist, like a REPL. Returns true and the values as text (tab-separated), or false and the error. The code has every capability; calling it needs eval from every plugin involved. With sandbox, it runs in a fresh environment that can read the editor and edit buffers and nothing else: what it would do beyond that (run programs or commands, change keys, reach files) fails with an error starting “needs approval:”.

on

on: ((event: "mode.changed", handler: (event: ModeChanged) -> ()) -> ())
	& ((event: "buffer.changed", handler: (event: BufferChanged) -> ()) -> ())
	& ((event: "keys.pending", handler: (event: KeysPending) -> ()) -> ())
	& ((event: "command.run", handler: (event: CommandRun) -> ()) -> ())
	& ((event: "lsp.diagnostics", handler: (event: DiagnosticsChanged) -> ()) -> ())
	& ((event: "message", handler: (event: Message) -> ()) -> ())
	& ((event: "control.request", handler: (event: ControlRequest) -> ()) -> ())
	& ((event: "control.closed", handler: (event: ControlClosed) -> ()) -> ())
	& ((event: "client.attached", handler: (event: ClientAttached) -> ()) -> ())
	& ((event: "client.detached", handler: (event: ClientDetached) -> ()) -> ())
	& ((event: "client.paste", handler: (event: ClientPaste) -> ()) -> ())
	& ((event: "buffer.opened", handler: (event: BufferChanged) -> ()) -> ())
	& ((event: "buffer.saved", handler: (event: BufferChanged) -> ()) -> ())
	& ((event: "buffer.closed", handler: (event: BufferClosed) -> ()) -> ())
	& ((event: "view.closed", handler: (event: ViewClosed) -> ()) -> ())
	& ((event: "view.resized", handler: (event: ViewResized) -> ()) -> ())
	& ((event: "pane.opened", handler: (event: PaneOpened) -> ()) -> ())
	& ((event: "view.scrolled", handler: (event: ViewScrolled) -> ()) -> ())
	& ((event: "selection.changed", handler: (event: SelectionChanged) -> ()) -> ())
	& ((event: "view.focused", handler: (event: ViewFocused) -> ()) -> ())
	& ((event: "ssh_agent.use", handler: (event: SshAgentUse) -> ()) -> ())
	& ((event: "mouse", handler: (event: MouseEvent) -> ()) -> ())
	& ((event: "option.changed", handler: (event: OptionChanged) -> ()) -> ())
	& ((event: "plugin.loaded", handler: (event: PluginLoaded) -> ()) -> ())
	& ((event: "file.changed", handler: (event: FileChanged) -> ()) -> ())
	& ((event: "plugin.unloaded", handler: (event: PluginUnloaded) -> ()) -> ())
	& ((event: "editor.started", handler: (event: {}) -> ()) -> ())
	& ((event: "editor.quitting", handler: (event: {}) -> ()) -> ())
	& ((event: "terminal.output", handler: (event: TerminalOutput) -> ()) -> ())
	& ((event: "terminal.exited", handler: (event: TerminalExited) -> ()) -> ())

Calls handler every time event happens, until greed.off removes it or the plugin unloads.

off

off: (event: EventName, handler: (event: any) -> ()) -> ()

Removes handler, added by this plugin with greed.on(event, handler). Does nothing if it’s not there.

echo

echo: (...any) -> ()

Shows a message to the user.

messages

messages: () -> { string }

The last messages shown, oldest first and whole (the status line shows a message’s first line).

view

view: (() -> View) & ((id: number) -> View?)

The focused view; with an id (view:id()), that view, or nil when it’s closed.

quit

quit: () -> ()

Asks the editor to exit.

line_numbers

line_numbers: (style: "absolute" | "relative" | "hybrid") -> ()

How line numbers count, where buffers show them: each line’s own number, “relative” to the cursor’s line (0 on it), or “hybrid”, relative with the cursor’s line showing its own.

scroll_margin

scroll_margin: (rows: number) -> ()

How many rows views keep in sight above and below the cursor as they follow it, at most half the view (core sets it from the scroll-margin option).

reveal

reveal: (how: "line" | "cursor" | "never", typing: ("line" | "cursor" | "never")?) -> ()

When text hidden by marks whose reveal is “auto” shows: “line” (on a cursor’s line, the default), “cursor” or “never”, as for a mark’s own reveal; typing, the same for those whose reveal is “typing” (as how without it). Core sets them as the mode changes (see core.reveal).

detach

detach: () -> ()

Lets the attached terminal go and keeps the editor running in the background, for greed attach to come back to.

sleep

sleep: (ms: number) -> ()

Waits ms milliseconds without blocking the editor. Works in commands and event handlers.

spawn

spawn: (f: (...any) -> ...any, ...any) -> ()

Runs f on its own, the way a command runs, and returns at once: it can wait (greed.sleep, greed.process.run, …) while the editor and the code that started it go on. For work in the background, like a status line piece refreshing.

stalls

stalls: () -> { { ms: number, plugin: string?, what: string, time: number } }

Runs of plugin code that held the editor up (50 ms or more), newest first, for tracing a freeze to its plugin and what it was doing: a command’s name, “the status line”, “loading”. ms is how long it took; time is when, in seconds since 1970 (as os.time() counts, with a fraction).

errors

errors: () -> { { plugin: string?, what: string, message: string, traceback: string, time: number } }

Errors from plugin code that nothing caught (a command, an event handler or a task failing), newest first, up to 100: the plugin, what it ran (“on buffer.opened”, a command’s name), the message, where in its Luau it failed, and when, in seconds since 1970.

profile

profile: { start: () -> (), stop: () -> { ProfileRow }, running: () -> boolean, loading: () -> { [string]: number } }

Counting where the editor’s time goes: every run of plugin code (each command, event handler, status line) and the editor’s own work (handling a key, parsing, drawing), by plugin and what it did. start begins, stop ends and returns the rows, the most time first; running says whether one is being taken. loading is how long each plugin’s code took to load, by name, in milliseconds, profile or not.

debug

debug: Debug

Debug lines and their topics, for seeing what the editor and plugins do: :debug and :debug-log use them.

See Debug.

now

now: () -> number

Milliseconds on the editor’s clock, for timing animations. While a timer wakes code, it reads the time the timer was due.

hostname

hostname: () -> string?

This machine’s name, or nil if the system doesn’t say.

animate

animate: (ms: number, step: (t: number) -> ()) -> ()

Calls step(t) about once a frame for ms milliseconds, with t going from 0 to 1, e.g. to fade a theme color or move a decoration. Works in commands and event handlers.

next_key

next_key: () -> string

Waits for the next key press and returns its name, e.g. “g” or “ctrl-s”. The key doesn’t run anything. Works in commands and event handlers.

keys

keys: Keys

See Keys.

process

process: Process

See Process.

rpc

rpc: Rpc

See Rpc.

http

http: Http

See Http.

secrets

secrets: Secrets

See Secrets.

terminal

terminal: Terminals

See Terminals.

image

image: Images

See Images.

scene

scene: Scenes

See Scenes.

pdf

pdf: Pdfs

See Pdfs.

html

html: Htmls

See Htmls.

signal

signal: () -> Signal

A one-shot value that one piece of code waits for and another sends, e.g. a tool waiting for the user’s review. wait works in commands and event handlers; a value sent before anyone waits is kept for them.

vouch

vouch: <A..., R...>(f: (A...) -> R..., A...) -> R...

Runs f with ... as your plugin’s own action: only your capabilities count for what it does, not those of the plugins whose code called you or started what runs. For services that check what they do themselves, like the models plugin sending a key only to its provider. Anything you vouch for, any plugin can make you do: vouch only for narrow, checked operations. It can wait.

statusline

statusline: (build: (ctx: StatusContext) -> StatusParts) -> ()

Sets the function that builds the status line. It runs for every frame.

object_finder

object_finder: (find: (kind: string, text: string) -> (any, string?)) -> ()

Sets the function typed commands find an “object” argument with: the object of kind the user typed text for, or nil and why not. It runs in the command, so it can wait. The core plugin sets it from core.objects.

set_menus

set_menus: (menus: { { title: string, items: { { label: string, command: string } } } }) -> ()

Sets the menus a window shows as its menu bar (on macOS, the system’s), replacing those before; each item runs its command. The core plugin keeps them, so add to require("@core").menus rather than calling this.

create_buffer

create_buffer: (kind: string, text: string?, opts: { readonly: boolean?, language: string? }?) -> Buffer

A new buffer that isn’t shown anywhere yet. It goes away when the last view showing it closes.

language_of

language_of: (path: string) -> string?

The language of the file at path, by its name or extension.

filetype

filetype: (language: string, spec: { extensions: { string }?, names: { string }? }) -> ()

Makes files with these extensions (without the dot) or exact names, like “Makefile”, be in language, replacing whatever it had before.

grammars

grammars: () -> { string }

The languages Greed has a grammar for, built in or loaded, sorted.

which

which: (program: string) -> string?

Where program is on PATH, or nil if it isn’t installed.

float

float: (buffer: Buffer, spec: FloatSpec?) -> View

Shows buffer in a view floating over the main one, and focuses it.

floats

floats: (opts: { hidden: boolean? }?) -> { View }

The floating views shown, the one in front last; with hidden = true, the hidden ones too.

panel

panel: (buffer: Buffer, spec: { side: ("left" | "right")?, width: (number | string)?, title: string?, focus: boolean? }?) -> View

Shows buffer in a panel beside the main view, which gives up the room. Defaults: the left side, 30 cells wide, focused. Close it with view:close().

buffers

buffers: () -> { Buffer }

Every open buffer.

buffer

buffer: (id: number) -> Buffer?

The buffer with id id (buffer:id()), or nil when it’s closed.

open

open: (path: string) -> ()

Opens a file in the main view.

load

load: (path: string) -> Buffer

The buffer for the file at path, opening it without showing it.

buffer_for

buffer_for: (path: string) -> Buffer?

The open buffer for the file at path, or nil when it isn’t open; it doesn’t open it. ~, . and .. are worked out and a relative path is from the folder Greed started in, so every spelling of a file finds its buffer.

diff

diff: (old: string, new: string) -> { { from: number, to: number, text: string } }

The changes that turn old into new, whole lines at a time: each replaces from..to (byte offsets into old) with text. Sorted.

commands

commands: () -> { CommandInfo }

Every command, sorted by name.

handlers

handlers: () -> { HandlerInfo }

Every event handler, by event and then the order they were added.

fuzzy

fuzzy: (query: string, items: { string }, opts: { case: ("smart" | "ignore" | "match")? }?) -> { number }

The 1-based indices of items that match query, best first. case says how it minds case: “smart” (the default: only when query has a capital letter), “ignore” or “match”; core.search.case() gives what the user chose.

fuzzy_positions

fuzzy_positions: (query: string, text: string, opts: { case: ("smart" | "ignore" | "match")? }?) -> { number }

The byte offsets of the characters in text that query matches, for highlighting them; empty if it doesn’t match. case as for fuzzy.

files

files: (dir: string?) -> { string }

Files under dir (default: the current directory), relative to it and sorted, skipping hidden and ignored files. Walked in the background while the caller can wait (a command, a handler, greed.spawn), so a big project doesn’t hold up the editor.

keymap

keymap: Keymap

See Keymap.

mode

mode: Mode

See Mode.

option

option: Options

See Options.

history

history: History

See History.

clipboard

clipboard: Clipboard

See Clipboard.

base64

base64: { encode: (bytes: string) -> string, decode: (text: string) -> string? }

Base64, as data goes in JSON, like an image for a model: encode takes bytes, decode gives them back, or nil for text that isn’t base64.

client

client: Client

See Client.

lsp

lsp: Lsp

See Lsp.

fs

fs: Fs

See Fs.

hash

hash: Hash

See Hash.

compare

compare: Compare

See Compare.

query

query: Query

See Query.

index

index: IndexModule

See IndexModule.

text

text: Text

See Text.

control

control: Control

See Control.

json

json: Json

See Json.

sikt

sikt: Sikt

See Sikt.

project

project: Projects

See Projects.

tab

tab: Tabs

See Tabs.

session

session: Sessions

See Sessions.

ssh_agent

ssh_agent: SshAgent

See SshAgent.

plugin

plugin: Plugins

See Plugins.

syntax

syntax: Syntax

See Syntax.

theme

theme: Theme

See Theme.

Range

A range of text. anchor is where it started and head is where the cursor is; a cursor is a range where the two are equal.

anchor

anchor: number
head: number

Selection

One or more ranges, sorted and never overlapping. primary is the 1-based index of the main range.

ranges

ranges: { Range }

primary

primary: number

Edits

Collects the edits made inside Buffer:edit. They are applied together, as one undoable change, when the callback returns.

insert

insert: (self: Edits, pos: number, text: string) -> ()

delete

delete: (self: Edits, from: number, to: number) -> ()

replace

replace: (self: Edits, from: number, to: number, text: string) -> ()

select

select: (self: Edits, selection: Selection) -> ()

Sets the selection after the edit (of every view showing the buffer, when the buffer didn’t come from a view). Without this, the current selection is moved along with the text: a cursor ends up after text inserted where it is, and after the new text of a replace or delete that covers it; a range doesn’t grow to take in text inserted at its edges.

Buffer

Open text, backed by a file or not. Two handles to the same buffer are equal (==).

id

id: (self: Buffer) -> number

Its id, even after it was closed.

valid

valid: (self: Buffer) -> boolean

Whether it is still open. Other methods fail once it was closed.

len

len: (self: Buffer) -> number

Length in bytes.

text

text: (self: Buffer) -> string

slice

slice: (self: Buffer, from: number, to: number) -> string

line_count

line_count: (self: Buffer) -> number

line_of

line_of: (self: Buffer, pos: number) -> number

The line pos is on.

line_start

line_start: (self: Buffer, line: number) -> number

line_end

line_end: (self: Buffer, line: number) -> number

The end of line, before its line break.

line_text

line_text: (self: Buffer, line: number) -> string

The text of line, without its line break.

display_column

display_column: (self: Buffer, pos: number, tab_width: number?) -> number

The screen column pos is drawn at in its line: wide characters take two columns and tabs reach the next tab stop, every tab_width columns (the buffer’s own if not given).

at_display_column

at_display_column: (self: Buffer, line: number, col: number, tab_width: number?) -> number

The position in line drawn at screen column col: the start of the character covering it, or the line’s end if the line is shorter.

char_at

char_at: (self: Buffer, pos: number) -> string?

The character at pos, or nil at the end of the buffer.

next_char

next_char: (self: Buffer, pos: number) -> number

prev_char

prev_char: (self: Buffer, pos: number) -> number

sentence

sentence: (self: Buffer, pos: number) -> (number, number)

The start and end of the sentence around pos, without the spaces after it. Sentences end at blank lines.

kind

kind: (self: Buffer) -> string

What the buffer is: “file”, “terminal”, …

path

path: (self: Buffer) -> string?

project

project: (self: Buffer) -> number?

The id of the project it was opened in.

readonly

readonly: (self: Buffer) -> boolean

True if only plugins can change the text: edits from keys and undo are refused.

set_readonly

set_readonly: (self: Buffer, readonly: boolean) -> ()

readonly_before

readonly_before: (self: Buffer) -> number?

Where the read-only start of the text ends, when only its start is (set_readonly_before).

set_readonly_before

set_readonly_before: (self: Buffer, pos: number?) -> ()

Makes the text before pos read-only, like set_readonly, and the rest writable, as a transcript above the box you write in; nil makes it all writable. The place moves with edits: what plugins insert there joins the read-only part, what you type there doesn’t. Typing and pasting with a cursor in the read-only part go to the end (core.writable).

name

name: (self: Buffer) -> string?

The name it was given, for a buffer without a file, like a terminal’s “nu ~/src”.

set_name

set_name: (self: Buffer, name: string?) -> ()

Names it where it shows (the tab line, float titles, the status line); nil or “” leaves it unnamed.

title

title: (self: Buffer) -> string

What it’s called where it shows: its file’s name, the name it was given, “untitled” for a file not saved yet, or its kind.

line_numbers

line_numbers: (self: Buffer) -> boolean

Whether the main view shows line numbers beside it (the default).

set_line_numbers

set_line_numbers: (self: Buffer, on: boolean) -> ()

at_bottom

at_bottom: (self: Buffer) -> boolean

Whether its views show it against their bottom edge while it’s shorter than them, as a chat’s messages sit on its box, and never scroll past its end; off by default, from the top.

set_at_bottom

set_at_bottom: (self: Buffer, on: boolean) -> ()

tab_width

tab_width: (self: Buffer) -> number

How many columns apart its tab stops are, as it’s drawn; 4 until set. Core sets it from the language or the “tab-width” option.

set_tab_width

set_tab_width: (self: Buffer, width: number) -> ()

Sets how many columns apart its tab stops are, at least 1.

views

views: (self: Buffer) -> { View }

The views showing it.

kept

kept: (self: Buffer) -> boolean

Whether it stays open while nothing shows it, though it has no file.

set_kept

set_kept: (self: Buffer, kept: boolean) -> ()

Keeps it open while nothing shows it, like a terminal to come back to; with false it goes once nothing shows it (right away if nothing does now).

set_screen_size

set_screen_size: (self: Buffer, size: { rows: number, cols: number, note: string?, cursor_row: number? }?) -> ()

Lays the text out at rows by cols in every view, whatever room a view has, like a terminal whose program has one screen size for one client: the screen is the buffer’s last rows lines. A client whose view is another size crops it (a terminal), keeping row cursor_row (0-based, where the program’s cursor is) in sight, or scales it (a window), and shows note (default “COLSxROWS”) in the room left over. nil lays it out at each view’s own size again.

screen_size

screen_size: (self: Buffer) -> { rows: number, cols: number, note: string?, cursor_row: number? }?

The size set_screen_size set, if any.

set_keys

set_keys: (self: Buffer, keys: { [string]: string }?) -> ()

Binds single keys for this buffer alone, e.g. { y = "answer-yes" }, in every mode and ahead of every other binding, while it has focus. Replaces what was bound for it before; nil drops them.

forget_history

forget_history: (self: Buffer) -> ()

Stops keeping undo history, for buffers whose edits nobody undoes, like a terminal’s: what’s kept goes, and later edits aren’t kept.

clear_history

clear_history: (self: Buffer) -> ()

Lets go of the undo history so far and keeps later edits: undo can’t go back past now, as at a shell’s prompt after a command runs.

language

language: (self: Buffer) -> string?

The language the text is highlighted as, e.g. “rust”.

set_language

set_language: (self: Buffer, language: string?) -> ()

Sets the language, or with nil goes back to the one the file’s extension implies.

tree

tree: (self: Buffer) -> Node?

The root of the syntax tree, or nil if the language has no grammar or the buffer is too big to parse. Just after an edit, when parsing again would hold the editor up, it’s the tree before with the edit applied (nodes moved with the text) until the new one is in.

node_at

node_at: (self: Buffer, from: number, to: number?) -> Node?

The smallest named node covering from..to (default: just from).

query

query: (self: Buffer, source: string, range: { from: number?, to: number? }?) -> { { [string]: Node } }

Runs a tree-sitter query over the buffer, or only for matches overlapping from..to, e.g. "(function_item name: (identifier) @name) @fn". One table per match, from capture name to node. Errors on a query the language’s grammar can’t compile; a buffer without a grammar has no matches, so any query gives an empty list there.

edit

edit: (self: Buffer, f: (e: Edits) -> (), opts: { undo: boolean? }?) -> ()

Edits the buffer: f records edits on e, and they are applied together, as one undoable change, when it returns. With undo = false the change isn’t kept to undo, like output streaming in above where someone types: undo skips it and still takes back only what the steps before it did (redo branches are dropped).

save

save: (self: Buffer, path: string?) -> ()

Writes the buffer to its file, or to path, which becomes its file.

modified

modified: (self: Buffer) -> boolean

True if the text changed since it was opened or last saved.

version

version: (self: Buffer) -> number

A number that grows with every edit, for caches that follow the text.

reload

reload: (self: Buffer) -> boolean

Reads its file again, as an edit by “external” that undo can take back, and counts it as saved. Returns whether the text changed.

close

close: (self: Buffer) -> ()

Closes the buffer, unsaved changes and all. Errors while a view shows it: show something else there first. Plugins hear “buffer.closed”.

decorate

decorate: (self: Buffer, ns: string, marks: { Mark }, within: { from: number, to: number? }?) -> ()

Replaces the marks in namespace ns (pick one per plugin feature, e.g. “search”). Marks move with edits; {} clears them. With within, only those starting from from up to (not at) to (default: the end) are replaced, e.g. on the lines an edit changed.

decorations

decorations: (self: Buffer, ns: string) -> { Mark }

The marks in namespace ns, where they are now.

marks_at

marks_at: (self: Buffer, pos: number) -> { Mark & { ns: string } }

The marks over pos in every namespace, each with its ns: those whose range holds it, and empty ones that start there.

track

track: (self: Buffer, pos: number, opts: { gravity: ("left" | "right")? }?) -> Anchor

Follows pos through edits. Text inserted exactly there goes before it with gravity = "right" (the default) and after it with “left”. Deleting text around it moves it to where the deletion was.

track_range

track_range: (self: Buffer, from: number, to: number, opts: { from: ("left" | "right")?, to: ("left" | "right")? }?) -> Tracked

Follows from..to through edits. from and to in opts are each end’s gravity, as for track; by default text inserted at either end stays outside. It’s deleted once all of its text is.

find

find: (self: Buffer, pattern: string, from: number?, opts: { backward: boolean?, wrap: boolean? }?) -> (number?, number?, string?)

The first match of the regex pattern starting at or after from (default 0), or with backward the last one starting before it; wrap goes round the other end. Returns its start and end, nil when nothing matches, or nil, nil and the error for a bad pattern.

find_all

find_all: (self: Buffer, pattern: string, from: number?, to: number?) -> ({ { from: number, to: number } }?, string?)

Every match of the regex pattern between from and to (default: the whole buffer), or nil and the error for a bad pattern.

kept_lines

kept_lines: (self: Buffer, filter: string, opts: { regex: boolean?, query: any?, section: string?, case: boolean?, from: number?, to: number? }?) -> { number }

The lines (0-based) a view’s filter of filter keeps of the buffer, with the same options as View.set_filter; of lines from to to (inclusive) only, with them.

find_groups

find_groups: (self: Buffer, pattern: string, from: number?, to: number?) -> ({ { { from: number, to: number } | false } }?, string?)

Like find_all, but each match is the whole match’s range followed by each group’s, false for a group that took no part.

history

history: (self: Buffer, filter: HistoryFilter?) -> { HistoryEntry }

The transactions applied to it, newest first: by author (“user”, “plugin”, “agent” or “external”), plugin, cause (the command that made them, “undo”, …), group, made at or after since (seconds, like time), at most limit.

text_before

text_before: (self: Buffer, id: number) -> string?

The text as it was before transaction id, or nil if the buffer has none by that id.

undo_tree

undo_tree: (self: Buffer) -> { nodes: { UndoNode }, current: number }

The undo tree: every state the text has been in, from node 0 (as it was loaded) on, each with the step before it as parent; undo goes to the parent and redo to the last child. current is the node the text is at.

undo_save

undo_save: (self: Buffer) -> string?

The undo tree as JSON, to keep it for after a restart; nil when nothing was done or the buffer keeps no undo history.

undo_restore

undo_restore: (self: Buffer, json: string) -> (boolean, string?)

Takes back an undo tree undo_save gave, for the text as it is now, as its current step: only while nothing was done since the buffer was loaded, and only if every step fits. Returns whether it did, and why not.

Node

A node in a buffer’s syntax tree, from buffer:tree(), buffer:node_at() or buffer:query(). It describes the buffer as it was when found; after an edit, find it again. tostring(node) shows its subtree, handy for writing queries.

kind

kind: string

The grammar’s name for it, e.g. “function_item” or “(”.

from

from: number

to

to: number

named

named: boolean

False for punctuation and keywords the grammar doesn’t name.

error

error: boolean

True for text the grammar couldn’t parse, or a missing piece it assumed.

field

field: string?

Its field name in its parent, e.g. “name” or “body”, if it has one.

parent

parent: (self: Node) -> Node?

children

children: (self: Node) -> { Node }

named_children

named_children: (self: Node) -> { Node }

Its children without the unnamed ones (punctuation, keywords).

child

child: (self: Node, field: string) -> Node?

The child in field field, e.g. fn:child("body").

next

next: (self: Node) -> Node?

The next named sibling.

prev

prev: (self: Node) -> Node?

The previous named sibling.

text

text: (self: Node) -> string

Its text. Errors if the buffer changed since the node was found.

Anchor

A position that moves with edits, from buffer:track. It goes when forgotten, when its buffer closes, or when the plugin that made it is unloaded.

pos

pos: (self: Anchor) -> number?

Where it is now, or nil once it’s gone.

forget

forget: (self: Anchor) -> ()

Stops following it.

Tracked

A range that moves with edits, from buffer:track_range. It goes as an Anchor does.

range

range: (self: Tracked) -> (number?, number?)

Where it is now, or nil once its text was deleted or it’s gone.

deleted

deleted: (self: Tracked) -> boolean

Whether all of its text was deleted, or it’s gone. Undo bringing the text back doesn’t change that.

forget

forget: (self: Tracked) -> ()

Stops following it.

MarkLine

A line a mark shows under its range: text, or pieces with styles of their own. On a float’s border (label, footer), a piece’s action is a command that a click on it runs, with any arguments after its name (“float-go 3”).

MarkLine = string | { { text: string, style: string?, action: string? } }

Mark

Text drawn with a style name, e.g. { from = 6, to = 11, style = "match" }. Text typed at either edge stays outside it.

from

from: number

to

to: number

style

style: string

line

line: boolean?

Style every whole line the mark touches, not just its text.

text

text: string?

Text to show that isn’t in the buffer, like an inlay hint, before the character at from. The cursor skips over it.

eol

eol: boolean?

Show text after the end of the line instead, cut off at the edge.

sign

sign: string?

A symbol for the sign column next to the line numbers, e.g. “E”.

gutter

gutter: string?

A style for the line number of each line the mark touches, e.g. “ui.gutter.diagnostic.error”.

above

above: boolean?

Draw over selections and cursors rather than under them.

overlay

overlay: boolean?

Draw text over the characters from from instead of inserting it, like a jump label. The text doesn’t move. Past a line’s end it goes on over the empty room there, after any eol text, a space only moving what follows along, so several can share it (like rulers).

wrapped

wrapped: boolean?

With text at the start of a line, draw it again at the start of each row the line wraps onto, like the bar beside a card.

conceal

conceal: boolean?

Hide the text, showing text (if any) in its place, e.g. the brackets of a [[link]], except where reveal says.

reveal

reveal: ("line" | "cursor" | "never" | "auto" | "typing")?

When concealed text shows: “line” (the default) when a cursor is on its line, “cursor” when a cursor is inside it past its start (a click leaves it hidden), “never”, “auto” as greed.reveal last said, so the marks needn’t be drawn again when that changes, or “typing” as it said for markup that shows only while typing, like a table’s borders.

fold

fold: boolean?

Hide the lines after the first one, up to the last, unless a cursor is in them, like a section folded under its heading.

peek

peek: boolean?

With fold, show the lines while a cursor is on the first line too, as a part hidden under the line that says when it shows.

nowrap

nowrap: boolean?

Don’t wrap the lines it touches: what’s past the right edge is out of sight, and the view scrolls sideways to the cursor (view:side_scroll()), as for a wide table.

plain

plain: boolean?

Draw the text without syntax highlighting, like a tool’s output in a Markdown buffer.

language

language: string?

Highlight the text as this language, by name or file extension (“bash”, “rs”), over the buffer’s own, like a command in a line that’s no language at all. Languages inside it are found too.

lines

lines: { MarkLine }?

Lines shown under the last line that aren’t in the buffer, like backlinks. The cursor never goes on them. Each is a string, or pieces with styles of their own on top of the mark’s, e.g. { { text = "x = " }, { text = "2", style = "diff.plus.change" } }.

image

image: { id: number, cols: number, rows: number, col: number?, row: number? }?

An image (from greed.image) drawn over cols by rows cells right of and below from, whatever text is there. col and row say which of its cells is at from, for an image cut off at the top or left. Shown in terminals that can show images.

scene

scene: { id: number, cols: number, rows: number, col: number?, row: number? }?

A scene (from greed.scene) drawn over cols by rows cells right of and below from by the clients that can draw one, as an image is; the text there is what the others show, so put the scene in characters there. col and row are as for an image; a negative row starts it that many rows below from.

action

action: string?

A command that clicking text runs, with the cursor put at from first, so the text works as a button, e.g. “proposal-accept”.

scale

scale: number?

How many times bigger the range’s text (and text) is, 1 to 4, e.g. 2 for a heading: each character takes that many cells across, and its row that many rows down. The window draws it big, and so does kitty (its text sizing); other terminals show it at the normal size.

data

data: any?

Anything to keep with the mark, given back where it is read: plain data (tables, strings, numbers, booleans), never drawn.

View

A buffer shown on screen, with its own selection. Two handles to the same view are equal (==).

id

id: (self: View) -> number

Its id, even after it was closed.

valid

valid: (self: View) -> boolean

Whether it is still open. Other methods fail once it was closed.

decorate

decorate: (self: View, ns: string, marks: { Mark }, within: { from: number, to: number? }?) -> ()

buffer:decorate for marks only this view draws, like blame for the line its cursor is on. It replaces only this view’s marks in ns; they go when the view closes.

selection

selection: (self: View) -> Selection

set_selection

set_selection: (self: View, selection: Selection) -> ()

cursor

cursor: (self: View) -> number

The head of the primary selection.

set_cursor

set_cursor: (self: View, pos: number) -> ()

Makes the selection a single cursor at pos.

visible

visible: (self: View) -> (number, number)

The start and end of the text on screen when the view was last drawn, or of the whole buffer before that.

size

size: (self: View) -> (number?, number?)

The rows and columns of text it had room for when last drawn; nil before it’s drawn. “view.resized” says when they change.

area

area: (self: View) -> { x: number, y: number, width: number, height: number }?

Where it was last drawn on the screen, in cells, its gutter included; nil before it’s drawn.

drawn_column

drawn_column: (self: View, pos: number) -> number

The column pos is drawn at in its line in this view, the line as one long row: hidden text (a table’s pipes, a link’s brackets) takes no room and text marks show takes theirs, as it looks now. Vertical moves aim for it, so a table’s column is kept.

at_drawn_column

at_drawn_column: (self: View, line: number, col: number) -> number

The position drawn at column col of line in this view, the line as one long row: the text there, or where the text drawn next starts when col is on text a mark shows or past the line’s end.

hidden_lines

hidden_lines: (self: View) -> { { from: number, to: number } }

The lines folds hide, and those outside the lines it is narrowed to, 0-based and inclusive.

narrow

narrow: (self: View, from: number?, to: number?) -> ()

Shows only lines from to to (0-based, inclusive) of its buffer, as a float showing one part of it; no arguments shows all of it again. Showing another buffer does too.

set_keys

set_keys: (self: View, keys: { [string]: string }?) -> ()

Binds single keys for this view alone, e.g. { right = "slide-next" }, in every mode and ahead of its buffer’s keys and every other binding, while it has focus; other views of the buffer keep theirs. Replaces what was bound for it before; nil drops them.

hide_marks

hide_marks: (self: View, namespaces: { string }?) -> ()

Leaves the marks in these namespaces out of what this view draws, e.g. { "lsp" } for slides without the problems’ squiggles; other views of the buffer still draw them. Replaces the list it had; nil or empty draws them all again.

set_padding

set_padding: (self: View, padding: { top: number?, left: number? }?) -> ()

Leaves rows empty above its text and cells empty left of it, e.g. { top = 4, left = 8 } for a slide’s margin; size() is then the room inside. Nil takes it away.

hide_cursor

hide_cursor: (self: View, hidden: boolean?) -> ()

Draws no cursor or selection of its own in this view (false draws them again), like a slide of text; the cursor is still there and moves.

narrowed

narrowed: (self: View) -> (number?, number?)

The first and last line it’s narrowed to, or nil when it shows all of its buffer.

set_filter

set_filter: (self: View, text: string?, opts: { regex: boolean?, query: any?, section: string?, case: boolean?, skip: number? }?) -> ()

Shows only the lines a filter keeps, among those it shows past the first skip; the others stay in the buffer, hidden in this view alone. text is what was typed, given back by filter(); with regex it’s a regex. Otherwise the lines query matches, a query core.query parsed (as the shell’s filters read one: query.luau there): its words anywhere in a line (minding case with case), its fields those of a line of JSON (dotted paths, through arrays) or logfmt, compared as greed.compare does, and key=value found in the text of other lines; without a query, every word of text. A section (“status.conditions”) keeps the indented text (YAML, indented JSON) under those keys, with the keys above what shows. A line with a cursor on it shows anyway. Nil or empty shows every line again, and so does showing another buffer.

filter

filter: (self: View) -> string?

What set_filter was given, while it filters.

side_scroll

side_scroll: (self: View) -> number

How many columns the lines that don’t wrap (a mark’s nowrap) are scrolled to the left.

set_side_scroll

set_side_scroll: (self: View, columns: number) -> ()

Scrolls the lines that don’t wrap columns to the left. Drawing scrolls again if the primary cursor is on such a line and would be out of sight, so move it first.

scroll

scroll: (self: View) -> number

The 0-based line at the top of the view.

set_scroll

set_scroll: (self: View, line: number) -> ()

Scrolls so line is at the top. Drawing scrolls again if the primary cursor would be off screen, so move it first.

buffer

buffer: (self: View) -> Buffer

show

show: (self: View, buffer: Buffer) -> ()

Shows another buffer in this view, where the view left it if it showed it before, otherwise at the top.

focus

focus: (self: View) -> ()

Focuses this view, so keys go to it, showing its tab and project if it’s a pane or panel.

close

close: (self: View) -> boolean

Closes the view. Closing a tab’s last pane closes the tab; the project’s last pane can’t be closed, and returns false.

configure

configure: (self: View, spec: FloatSpec) -> boolean

Changes how a floating view is shown; fields left out stay as they are. False, changing nothing, if it isn’t floating; fails if it was closed.

set_title

set_title: (self: View, title: string?) -> boolean

Gives a panel or floating view the title title, nil or “” for none; false if it’s neither.

raise

raise: (self: View) -> boolean

Brings a floating view in front of the other floats; false if it isn’t floating.

float_spec

float_spec: (self: View) -> FloatSpec?

How a floating view is shown, as greed.float takes it; nil if it isn’t floating.

is_pane

is_pane: (self: View) -> boolean

Whether it’s a pane of a tab, rather than a panel or a floating view.

split

split: (self: View, dir: "left" | "right" | "up" | "down", buffer: Buffer?) -> View

Opens a pane beside this one on its dir side, showing buffer, or this view’s buffer as it shows it, and focuses it. Fails if this view isn’t a pane.

neighbor

neighbor: (self: View, dir: "left" | "right" | "up" | "down") -> View?

The pane next to this one on its dir side, as last drawn: of several, the one active most recently.

resize

resize: (self: View, dir: "left" | "right" | "up" | "down", cells: number) -> boolean

Moves this pane’s edge on its dir side by cells (negative to shrink). False when no pane is on that side. A panel moves the edge by the main view, and only that.

undo

undo: (self: View) -> boolean

Undoes the last change. Returns false if there was nothing to undo.

undo_to

undo_to: (self: View, id: number) -> boolean

Takes the buffer to node id of its undo tree, undoing and redoing on the way, as one move; redo follows that branch from then on. False if there’s no such node or the text is there already.

redo

redo: (self: View) -> boolean

Context

What a command gets when it runs.

view

view: View

See View.

buffer

buffer: Buffer

See Buffer.

keys

keys: string?

The keys that ran the command, e.g. “g g”.

char

char: string?

The character typed, when a single printable key ran the command.

args

args: { string }

Arguments, e.g. from the command line; empty when a key ran it.

values

values: { [string]: any }

The arguments by name: for a typed command, parsed (a number, a boolean, a full path, the core.Object), nil for an optional one left out; otherwise the words as given.

force

force: boolean

Go ahead even if the command would normally refuse, like :q! quitting with unsaved changes.

count

count: number?

The number typed before the keys, in modes with counts on.

client

client: number

The id of the client it runs for, whose view and selections these are.

ArgSpec

An argument a command takes, for completion, help and checking. Giving any of a command’s arguments a type has them all checked before it runs, and parsed into ctx.values.

name

name: string

doc

doc: string?

complete

complete: string?

What completes it, e.g. “file”, “command”, “option” or “buffer”. Without it, the command line completes from type.

type

type: string?

What it is: “string” (the default), “number”, “boolean” (true/false, yes/no, on/off), “file” or “folder” (one that exists, from the project’s root), “choice” (one of choices), “object” (an object of kind, as core.objects has them), or “rest” (the rest of the words, joined by spaces; last only).

optional

optional: boolean?

It can be left out; every argument after it must be optional too.

choices

choices: { string }?

The words a “choice” can be.

kind

kind: string?

The kind of object an “object” is, e.g. “note” or “pod”.

CommandSpec

name

name: string

Plain words with dashes, e.g. “select-line”.

doc

doc: string?

args

args: { ArgSpec }?

run

run: (ctx: Context) -> ()

CliSpec

A command for the command line, run as greed NAME ARGS in an editor with no screen. run can wait like a command; what it echoes and returns is printed, and an error makes greed fail.

name

name: string

Plain words with dashes, e.g. “bring”.

doc

doc: string?

usage

usage: string?

What follows the name, e.g. “HOST [PLUGIN]”.

run

run: (args: { string }) -> string?

Layer

A keymap layer. Leave mode or kind out to match any. In place of a mode: layer names a layer that isn’t a mode, like the “leader”, which every editing style enters its own way (space, or ctrl-space without modes); role is an editing role (“command”, “typing”, “selecting”) in every style, and with style in that style only.

mode

mode: string?

layer

layer: string?

role

role: string?

style

style: string?

kind

kind: string?

Keymap

bind

bind: (layer: string | Layer, bindings: { [string]: string }) -> ()

Binds key sequences to command names, e.g. { ["g g"] = "goto-start" }. layer is a mode name or a Layer.

unbind

unbind: (layer: string | Layer, keys: { string }) -> ()

Hides what each key sequence runs in layer, e.g. { "w", "g g" }. Removing (or reloading) the plugin that unbound them brings them back.

clear

clear: (layer: string | Layer) -> ()

Hides everything bound in layer so far, to start it over. Bindings made afterwards, by any plugin, apply as usual.

counts

counts: (mode: string) -> ()

Makes digits typed before a key sequence in mode a count, which the command gets as ctx.count. A leading 0 stays a key.

isolate

isolate: (mode: string) -> ()

Makes mode use only keys bound in it (and its fallback), skipping inherited ones and those bound for every mode or for a buffer kind, e.g. for a terminal that takes every key.

inherit

inherit: (mode: string, parent: string | Layer, prefixes: { string }?) -> ()

Makes mode fall back to parent’s keys for sequences starting with one of prefixes (e.g. { "space", ":" }), or for every key without them. Keys bound in mode itself come first; what parent inherits applies in turn. parent can be a layer like { role = "typing" }.

inherit_first

inherit_first: (mode: string, parent: string | Layer) -> ()

Makes mode use parent’s keys ahead of its own, e.g. { style = "vim", role = "command" } for the Vim style’s command mode. core.style.define does this for each style’s roles.

enter

enter: (mode: string, keys: string, layer: string) -> ()

Makes keys typed in mode lead into layer, so what’s bound there works after them, e.g. enter("helix", "space", "leader"). It comes ahead of the mode’s own keys. core.style.define does this for each style’s leader.

fallback

fallback: (mode: string, command: string) -> ()

The command that handles a single unbound key in mode. A mode without one uses that of a mode it inherits every key from.

next

next: (keys: string?) -> { { key: string, command: string? } }

The keys that can follow keys (e.g. “space”) in the current mode, and the command each runs. Keys without a command start longer sequences.

find

find: (command: string?) -> { { layer: string, keys: string, command: string } }

Every key sequence that runs command (every binding, without one), the layer it’s bound in (a mode name, a named layer like “leader”, “role:typing” or “vim:command”, or “global”) and its command.

active

active: () -> { { keys: string, command: string } }

Every key sequence that runs a command in the current mode and buffer, through the layers it enters and inherits (the leader’s as “space f”), less those a more specific layer hides.

overlay

overlay: (bindings: { [string]: string }?) -> ()

Binds single keys for the next key press only, over every layer, e.g. { ["1"] = "hint-1" }; any other key drops them and does what it always does. Nil drops them now.

resolve

resolve: (keys: string) -> (string?, boolean)

What keys runs in the current mode: the command, or nil and whether more keys could still finish a sequence.

describe

describe: (keys: string) -> { { layer: string, command: string, plugin: string } }

What keys runs in the current mode and buffer and what that hides: the binding in each layer they’re bound in, most specific first, each followed by those it hides in its own layer, with the plugin that bound it. The first runs.

Mode

get

get: () -> string

set

set: (name: string) -> ()

Switches mode, emitting “mode.changed” if it changed. A mode exists once keys are bound in it or it has a fallback, a parent, counts or a cursor shape; switching to one that doesn’t is an error listing those that do.

set_cursor

set_cursor: (mode: string, shape: "block" | "bar" | "underline") -> ()

Sets how the cursor looks in mode; modes without a shape get a block.

cursor_of

cursor_of: (mode: string?) -> "block" | "bar" | "underline"

The cursor shape of mode, or of the current mode. A block or underline sits on a character, the last of a selection going forward; a bar sits between characters.

OptionValue

OptionValue = boolean | number | string

Options

define

define: (spec: { name: string, doc: string?, default: OptionValue, choices: { OptionValue }?, needs: string? }) -> ()

Defines an option. With choices, it takes only those values (the default among them), and :set completes them. With needs, a capability like “proc”, only code that has it, or you yourself (:set, your config), may set it: for an option whose value is run, like a command line. A plugin can’t define an option another plugin defined.

get

get: (name: string) -> OptionValue?

The option’s value for the acting client: its own, if it has one, else everyone’s.

set

set: (name: string, value: OptionValue?, opts: { client: boolean? }?) -> ()

Sets an option for every client; fails on an unknown name, the wrong type or a value that isn’t one of its choices. With client, sets a value of the acting client’s own instead, like a window’s font size, which nil takes away again; setting it for every client takes away each client’s own.

list

list: () -> { OptionInfo }

Every option, sorted by name.

OptionInfo

name

name: string

doc

doc: string

value

value: OptionValue

See OptionValue.

default

default: OptionValue

See OptionValue.

choices

choices: { OptionValue }

The values it can take; empty when any value of its type will do.

owner

owner: string

The plugin that defined it.

set_by

set_by: string?

The plugin that last set it (your config is a plugin too), if anything has.

source

source: string?

Where it was defined, e.g. “core/edit.luau:12”, and the file and line when that file is on disk.

path

path: string?

line

line: number?

HandlerInfo

An event handler, as greed.handlers() lists it.

event

event: string

owner

owner: string

The plugin that added it.

source

source: string?

path

path: string?

line

line: number?

Keys

Recording what’s typed and feeding keys back, for macros and repeating changes. Recordings have names (macros use the default, “”), so several can run at once.

record

record: (name: string?, opts: { fed: boolean? }?) -> ()

Starts keeping every key typed in the recording name, until stop; with fed, keys feed presses too.

stop

stop: (name: string?) -> { string }?

Stops the recording name and returns the keys typed, e.g. { "i", "x", "esc" }, or nil if it wasn’t recording.

recording

recording: (name: string?) -> boolean

feed

feed: (keys: string) -> ()

Presses the keys of a space-separated sequence as if they were typed. Only recordings started with fed keep them. What they run can do only what this plugin may (unless it has “commands”), and they don’t answer a command waiting for you to press a key. A command that works long enough to give the editor a turn finishes before the next key; one waiting on a timer or a job doesn’t hold them up.

HttpRequest

A request for greed.http. method defaults to POST with a body and GET without; timeout is in milliseconds, for the whole request, and head_timeout for the status and headers alone, which limits a stream’s wait without limiting its body. With save, request writes a successful (2xx) response’s body to that file as it arrives, creating its folders, and returns an empty body; the file appears only once it’s whole. Other responses come back as usual and nothing is written. Saving needs “fs.write”.

url

url: string

method

method: string?

headers

headers: { [string]: string }?

body

body: string?

timeout

timeout: number?

head_timeout

head_timeout: number?

save

save: string?

HttpResponse

A whole response. Header names are lowercase.

status

status: number

headers

headers: { [string]: string }

body

body: string

HttpStream

A response whose body arrives in pieces. read waits for the next piece and returns it, nil at the end, or nil and why it failed; given timeout milliseconds, it gives up after them with nil and “timed out”, and the stream stays open for the next read. close stops reading, and a read waiting in another task returns nil.

status

status: number

headers

headers: { [string]: string }

read

read: (self: HttpStream, timeout: number?) -> (string?, string?)

close

close: (self: HttpStream) -> ()

Http

Requests over the network, each on a thread of its own so the editor never waits. Both wait like greed.sleep, so they work in commands and event handlers. A plugin needs the “net” capability, or “net:HOST” for one host.

request

request: (request: HttpRequest) -> (HttpResponse?, string?)

Sends a request and returns the whole response, or nil and why.

stream

stream: (request: HttpRequest) -> (HttpStream?, string?)

Sends a request and returns once the status and headers are in; read the body as it arrives, e.g. tokens from a model.

Secrets

Secrets like API keys, kept out of config and plugin source: from the environment (GREED_SECRET_NAME, or the usual variable, e.g. ANTHROPIC_API_KEY), the system keyring, or Greed’s own secrets file. Both wait like greed.sleep. A plugin needs “secrets:NAME” for each secret it reads, or “secrets” for all.

get

get: (name: string) -> (string?, string?)

The secret name, or nil if it isn’t set anywhere; then also why when the system keyring couldn’t be reached (e.g. secret-tool isn’t installed), since it may be kept there.

set

set: (name: string, value: string) -> (string?, string?)

Keeps value as the secret name: in the keyring if it can be reached, otherwise in Greed’s secrets file. Returns where it went (with why not the keyring, when it couldn’t be reached), or nil and why not.

variable

variable: (name: string) -> string

The environment variable that sets the secret name, to tell someone: the usual one, like ANTHROPIC_API_KEY, or GREED_SECRET_NAME. Reads nothing, so it needs no capability.

RunOptions

How greed.process.run runs a program: stdin is its input, cwd its folder; in env, false leaves a variable out of what it inherits. With timeout (milliseconds) it’s killed if it runs longer; with group, it gets a process group of its own, which that reaches too. on_start(child) gets it as it starts, to stop it from elsewhere.

RunOptions = { stdin: string?, cwd: string?, env: { [string]: string | false }?, timeout: number?, group: boolean?, on_start: ((child: Child) -> ())? }

Ran

How a program greed.process.run ran went: its exit code, or the signal that ended it, what it printed, and whether its timeout ended it.

Ran = { code: number?, signal: string?, stdout: string, stderr: string, timed_out: boolean }

Process

Running other programs.

run

run: (command: { string }, opts: RunOptions?) -> (Ran?, string?)

Runs command (the program, then its arguments) to its end as opts say and returns how it went; nil and the error if it couldn’t start. Like a spawned program it’s the plugin’s, and goes with it. It waits like greed.sleep, so only in commands, event handlers and greed.spawn.

spawn

spawn: (command: { string }, opts: { cwd: string?, env: { [string]: string | false }?, stderr: ("keep" | "stream")?, group: boolean? }?) -> (Child?, string?)

Starts command to talk to over its input and output, like an agent speaking JSON-RPC, and returns at once; nil and the error if it couldn’t start. It runs until it exits, is killed, or the plugin that started it unloads. In env, false leaves a variable out of what it inherits. With stderr = "stream", what it prints as errors arrives from read too, in the order it comes; by default it’s only kept for child:stderr(). With group, it starts a process group of its own, which kill and signal reach, so the programs it starts end with it.

env

env: (name: string) -> string?

The editor’s own environment variable name, as the programs it starts inherit it, or nil if it isn’t set: env("SHELL").

RpcOptions

How greed.rpc.start talks to a program. framing is how its messages are told apart: “headers” (Content-Length, as language servers and debug adapters write them; the default) or “lines” (one a line, as agents over ACP). on_request(method, params) answers its requests, returning the result or nil and an error; on_notify(method, params) hears its notifications; each runs in a coroutine of its own, so it may wait. on_exit(stderr) is called once it exits, with the last lines of its error output.

RpcOptions = { cwd: string?, env: { [string]: string | false }?, framing: ("headers" | "lines")?, on_request: ((method: string, params: any) -> (any, string?))?, on_notify: ((method: string, params: any) -> ())?, on_exit: ((stderr: string) -> ())? }

RpcConnection

A JSON-RPC connection to a program, from greed.rpc.start.

request

request: (self: RpcConnection, method: string, params: any) -> (any, string?)

Sends a request and waits for its result, or nil and the error. Waits like greed.sleep, so only in commands, event handlers and greed.spawn.

notify

notify: (self: RpcConnection, method: string, params: any) -> boolean

Sends a notification; false if it couldn’t go.

alive

alive: (self: RpcConnection) -> boolean

Whether the program is still running.

stderr

stderr: (self: RpcConnection) -> string

The last lines of its error output.

close

close: (self: RpcConnection) -> ()

Ends the connection; the program’s input closes and it’s killed if it doesn’t exit soon after.

Rpc

JSON-RPC 2.0 with a program, on the transport language servers use.

start

start: (command: { string }, opts: RpcOptions?) -> (RpcConnection?, string?)

Starts command and talks JSON-RPC with it; nil and the error if it couldn’t start. Needs “proc”. The connection is the plugin’s, and goes with it.

Child

A program started with greed.process.spawn.

pid

pid: number

write

write: (self: Child, text: string) -> boolean

Sends text to its input; false once that’s closed.

read

read: (self: Child) -> (string?, ("stdout" | "stderr")?)

Waits for the next piece of what it prints, and returns it with the output it came from, “stdout” or “stderr” (only with stderr = "stream"); nil once it exited and everything was read. Only in commands, event handlers and greed.spawn.

close

close: (self: Child) -> ()

Closes its input, which tells most programs to finish.

kill

kill: (self: Child) -> ()

Ends it (and with group, its process group) with KILL.

signal

signal: (self: Child, name: string) -> boolean

Sends it a signal by name, like “INT”, “TERM”, “HUP” or “QUIT”; with group, to its process group, even after it exited, as a shell signals a job. Returns whether it went.

wait

wait: (self: Child) -> (number?, string?)

Waits for it to exit and returns its exit code, or nil and the name of the signal that ended it, like “INT”.

stderr

stderr: (self: Child) -> string

The end of what it printed as errors so far.

TerminalRow

A line of a terminal: its text, and the parts with a style of their own (byte offsets, 0-based, to exclusive), styled with inline names like “=fg:red bold”.

text

text: string

spans

spans: { { from: number, to: number, style: string } }

images

images: { { from: number, id: number, col: number, row: number, cols: number, rows: number } }

Images on the row, as runs of cells from byte from: from the image’s cell (col, row) on, of an image cols by rows cells. id is a greed.image id, for a mark’s image.

links: { TerminalLink }

Links the program printed (OSC 8), as byte ranges and where they go.

wrapped

wrapped: boolean

Whether the line carries on on the next row: the program printed past the last column and the terminal wrapped it.

TerminalModes

The modes a terminal’s program set, from terminal:modes().

alternate

alternate: boolean

A full screen program, like an editor or a pager, is showing.

canonical

canonical: boolean

Input goes to the program a line at a time; off in raw mode, which editors and prompts set.

echo

echo: boolean

Typed text is echoed; off while a program reads a password.

mouse

mouse: boolean

The program asked for mouse events.

app_cursor

app_cursor: boolean

Arrow keys are sent in application mode.

bracketed_paste

bracketed_paste: boolean

Pastes are marked as pastes.

TerminalLink = { from: number, to: number, uri: string }

TerminalScreen

What a terminal shows.

rows

rows: { TerminalRow }

cursor

cursor: { row: number, col: number }?

The cursor’s row (0-based) and byte offset in it, unless the program hid it.

alternate

alternate: boolean

Whether a full screen program, like an editor or a pager, is showing.

Terminal

A program running in a terminal. Two handles to the same terminal are equal (==).

id

id: (self: Terminal) -> number

Its id, even after it was closed.

valid

valid: (self: Terminal) -> boolean

Whether it is still open. Other methods fail once it was closed.

screen

screen: (self: Terminal) -> TerminalScreen

scrollback

scrollback: (self: Terminal, from: number?) -> { first: number, rows: { TerminalRow } }

The lines that scrolled off the top, from line from (counting from the terminal’s first line) on, or from the oldest one kept. first is the number of the first line returned.

marks

marks: (self: Terminal, from: number?) -> { TerminalMark }

The places the shell marked (OSC 133) on line from (counting as scrollback does) and after, oldest first: where a prompt starts, where the typed command starts, where its output starts, and where it was done, with its exit code if the shell said. col is a byte in the line’s text.

marks_made

marks_made: (self: Terminal) -> number

How many marks the shell has made so far, to tell when there are new ones without asking for them all.

cwd

cwd: (self: Terminal) -> string?

The folder the shell last said it’s in (OSC 7), or the one it started in.

write

write: (self: Terminal, text: string) -> ()

Sends text to the program as if typed. This and the other methods that send input need “proc”: the plugin that started the terminal has it through the handle it got; others with one from an event need their own.

key

key: (self: Terminal, name: string) -> ()

Sends a key, e.g. “ctrl-c” or “up”, as a terminal encodes it.

paste

paste: (self: Terminal, text: string) -> ()

Sends pasted text, marked as a paste if the program asked for that.

resize

resize: (self: Terminal, rows: number, cols: number) -> ()

Changes its size, kept to between 1 by 1 and 1024 rows by 2048 columns.

wants_mouse

wants_mouse: (self: Terminal) -> boolean

Whether the program asked for mouse events, as editors and htop do.

modes

modes: (self: Terminal) -> TerminalModes

The modes the program set: the alternate screen, line input and echo (from the terminal’s settings), mouse, application cursor keys and bracketed paste.

mouse

mouse: (self: Terminal, kind: string, col: number, row: number, which: string?, mods: { ctrl: boolean?, alt: boolean?, shift: boolean? }?) -> boolean

Sends a mouse event at the program’s screen cell (col, row), 0-based, if it asked for that kind: kind as in a MouseEvent, with a button or a scroll direction. Returns whether it was sent.

title

title: (self: Terminal) -> string?

What the program called its window, if it did.

notices

notices: (self: Terminal) -> { { title: string?, body: string } }

The notifications the program sent since this was last asked, oldest first (the latest 16): OSC 9;BODY or OSC 777;notify;TITLE;BODY, as many programs and shells send them.

progress

progress: (self: Terminal) -> { state: "going" | "error" | "busy" | "paused", percent: number? }?

How far the program last said it got (ConEmu’s OSC 9;4): “going” with percent 0 to 100, “error”, “busy” (no telling how far) or “paused”; nil when it hasn’t said, or said it’s done.

program

program: (self: Terminal) -> string

The name of the program it started, like “nu” or “cargo”: its file name, or the shell’s for a terminal started without a command.

exit_code

exit_code: (self: Terminal) -> number?

The program’s exit code, once it has ended.

busy

busy: (self: Terminal) -> boolean

Whether a program other than the one it started is in the foreground, like a command its shell runs. False once it has ended.

kill

kill: (self: Terminal) -> ()

Asks the program to end.

interrupt

interrupt: (self: Terminal) -> boolean

Interrupts what runs in the foreground, as ctrl-c does, even in the moment after it starts, before a typed ctrl-c would reach it. Returns whether it went.

close

close: (self: Terminal) -> ()

Ends the program and lets the terminal go; its handle stops working.

Terminals

Programs in terminals. A terminal belongs to the plugin that started it.

spawn

spawn: (spec: { command: { string }?, cwd: string?, env: { [string]: string | false }?, rows: number, cols: number, scrollback: number? }) -> Terminal

Starts command (the program, then its arguments; the user’s shell without) in a terminal of rows by cols. Its output arrives as “terminal.output” events and its end as “terminal.exited”. scrollback lines are kept above the screen (default 10000). The size is kept to between 1 by 1 and 1024 rows by 2048 columns. In env, false leaves a variable out of what the program inherits.

TerminalMark

A place a shell marked in a terminal, from terminal:marks().

line

line: number

col

col: number

kind

kind: "prompt" | "command" | "output" | "done"

code

code: number?

The exit code, for “done”, if the shell said.

TerminalOutput

A terminal printed something; read it with terminal:screen().

terminal

terminal: Terminal

See Terminal.

TerminalExited

The program in a terminal ended.

terminal

terminal: Terminal

See Terminal.

code

code: number

signaled

signaled: boolean

Whether a signal ended the program, rather than its own exit.

UndoNode

A state of a buffer’s text in its undo tree, from buffer:undo_tree().

id

id: number

0 is the text as loaded; later states have higher ids.

parent

parent: number?

children

children: { number }

Oldest first; redo follows the last.

time

time: number?

When the step was last added to, in seconds like os.time(); nil for node 0.

HistoryEntry

A transaction applied to a buffer, from buffer:history().

id

id: number

author

author: "user" | "plugin" | "agent" | "external"

plugin

plugin: string?

The plugin, for edits a plugin made.

cause

cause: string?

Why: the command it was made for, “undo”, “redo”, …

group

group: number?

The undo group it was made in.

time

time: number

When, in seconds since 1970.

changes

changes: { { from: number, to: number, text: string } }

What it replaced, in the text before it, in order.

HistoryFilter

author

author: string?

plugin

plugin: string?

cause

cause: string?

group

group: number?

since

since: number?

limit

limit: number?

History

start_group

start_group: () -> ()

Edits until end_group become one undo step.

end_group

end_group: () -> ()

new_group

new_group: () -> number

A group id nothing has used yet, for set_group.

group

group: () -> number?

The group edits go into now, if any.

set_group

set_group: (group: number?) -> ()

Puts the edits that follow, in every buffer, into group (one used before carries on), or with nil into none. Edits in a group undo as one step.

cause

cause: () -> string?

Why edits are being made: by default the command running.

set_cause

set_cause: (cause: string?) -> ()

Sets why the edits that follow are made, for the rest of this command.

undo_group

undo_group: (group: number) -> (number?, string?)

Undoes group in every buffer it changed, as one step. Returns how many buffers changed (0 if it was undone already), or nil and why not, when something was done on top of it since.

FloatSpec

How a floating view looks. Sizes are cells, or a share of the screen as a string like “60%” or “37.5%”, which keeps the float in proportion on clients with screens of other sizes; both default to “60%”.

title

title: string?

width

width: (number | string)?

height

height: (number | string)?

anchor

anchor: ("center" | "top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "cursor" | "above-cursor")?

Where it goes when x or y is left out: in the middle, at an edge or in a corner. “cursor” opens it just below the cursor (or above, near the bottom), like a completion menu; “above-cursor” prefers above, like signature help.

focus

focus: boolean?

Whether the view takes focus. Defaults to true.

x

x: (number | string)?

Where the outside of the border goes, from the screen’s left and top edges, in cells or like “37.5%”. Left out, the float goes where anchor says on that axis. It’s always kept on screen.

y

y: (number | string)?

tab

tab: boolean?

Whether it belongs to the tab it opens in: shown only with that tab, and closed with it, like a floating terminal. Otherwise it floats over every tab, like a picker. Defaults to false.

shared

shared: boolean?

Whether every client is shown it, like a review meant for everyone. Otherwise only the client it opened for is (the one acting then), as with a picker or a prompt, unless it belongs to a tab, which every client showing the tab sees. Defaults to false.

label

label: MarkLine?

Text at the right end of the top border, e.g. “‹ 2/5 ›”, or pieces with styles of their own. “” takes it off.

See MarkLine.

footer: MarkLine?

Text in the middle of the bottom border, as label takes it.

See MarkLine.

border

border: boolean?

Whether it has a border; defaults to true. Without one its text fills its whole box, like a one-line strip.

hidden

hidden: boolean?

Hides it: its view and buffer stay (a terminal keeps running), but it isn’t drawn, greed.floats() leaves it out and focus moves on. Focusing it shows it again.

CommandInfo

name

name: string

doc

doc: string

args

args: { ArgSpec }

usage

usage: string

How it’s typed, e.g. “kube-namespace [NAME]”.

owner

owner: string

The plugin that defined it.

source

source: string?

Where it was defined, e.g. “core/motions.luau:120”.

path

path: string?

The file and line it was defined on, when that file is on disk.

line

line: number?

BufferClosed

A buffer was closed. Only its id is left.

id

id: number

BufferChanged

buffer

buffer: Buffer

See Buffer.

from_line

from_line: number?

On “buffer.changed”: the first and last line (0-based, as the text is now) of what changed since the last “buffer.changed” for the buffer.

to_line

to_line: number?

ControlRequest

A request from the session socket, e.g. from greed ctl or an agent. Answer it with greed.control.reply.

id

id: number

client

client: string

“socket” for the session socket (greed ctl, greed mcp), “ide” for Claude Code’s IDE connection.

connection

connection: number?

The session socket connection it came on, for greed.control.send; nil for Claude Code’s IDE connection.

rpc_id

rpc_id: any

The JSON-RPC id as the client sent it, the one a later notifications/cancelled names; nil for a notification.

method

method: string

params

params: any

ControlClosed

A session socket connection closed, after its last request came.

connection

connection: number

The connection, as ControlRequest.connection gave it.

Signal

wait

wait: (self: Signal) -> any

Waits until a value is sent, and returns it.

send

send: (self: Signal, value: any) -> ()

Sends value to whoever waits. Only the first send counts.

ProjectInfo

A project: a folder with its own main view and panels.

id

id: number

root

root: string

current

current: boolean

Whether it’s the one shown.

Projects

list

list: () -> { ProjectInfo }

Every open project, in the order they were opened.

current

current: () -> ProjectInfo

open

open: (root: string) -> number

Opens a project rooted at root, with an empty main view, and shows it. Returns its id.

switch

switch: (id: number) -> boolean

Shows project id. False if there is none.

close

close: (id: number) -> boolean

Closes project id with its views and the buffers opened in it. The last project can’t be closed; false then.

Images

Images for marks to show. Each is kept until forgotten.

load

load: (path: string) -> (number?, string?)

Reads a PNG, JPEG or GIF file. Returns the image’s id, or nil and why not.

decode

decode: (bytes: string) -> (number?, string?)

The same, from the file’s bytes.

size

size: (id: number) -> (number?, number?)

Its width and height in pixels.

cells

cells: (id: number) -> (number?, number?)

How many cells it covers at its own size on the attached screen.

cell_size

cell_size: () -> (number, number)

A cell’s width and height in pixels on the attached screen.

forget

forget: (id: number) -> ()

Scenes

Small vector drawings, as charts are, for a mark’s scene: each client draws one as well as it can (an image in a terminal with kitty graphics), and the text under it is what the others show. A spec is { alt, items }: alt says what it shows, and items are line (points, style, weight), area (points, base, fill, opacity), rect (at, size, fill, style, opacity), dots (points, style, weight), text (at, text, style, align) and group (items, clip), in cells from the top left. require("@scene") draws a spec in characters.

new

new: (spec: { alt: string, items: { any } }) -> number

Keeps a scene and returns its id.

set

set: (id: number, spec: { alt: string, items: { any } }) -> boolean

Makes spec what scene id shows, at its next version; false when there’s no such scene.

forget

forget: (id: number) -> ()

Pdfs

PDF documents.

open

open: (path: string) -> (PdfDocument?, string?)

Reads the PDF at path. Returns the document, or nil and why not. It waits like greed.sleep, so only in commands, event handlers and greed.spawn.

PdfDocument

A PDF read with greed.pdf.open. Pages count from 1.

pages

pages: number

size

size: (self: PdfDocument, page: number) -> (number?, number?)

A page’s width and height in points (1/72 inch).

render

render: (self: PdfDocument, page: number, scale: number?) -> (number?, string?)

Draws a page at scale pixels per point (1 if not given) and returns it as a greed.image id, or nil and why not. Forget the image when done with it. Waits like greed.sleep.

text

text: (self: PdfDocument, page: number) -> (string?, string?)

The text on a page, line by line from the top, or nil and why not. Waits like greed.sleep.

Htmls

Web pages as text to read.

read

read: (html: string, url: string?) -> HtmlPage

What the page html reads as: its main content as Markdown, without menus, footers and banners, as a browser’s reader view shows it; a page with no article in it, like a list of links, as all its text. url is where it came from, for its links. Waits like greed.sleep.

HtmlPage

A page read with greed.html.read.

title

title: string?

byline

byline: string?

excerpt

excerpt: string?

The page’s own summary of itself, when it has one.

text

text: string

The text, as Markdown: links, lists, tables and code kept.

article

article: boolean

Whether text is an article found in the page, rather than all of the page’s text.

TabInfo

A tab of the shown project: panes laid out side by side and one above another.

id

id: number

name

name: string?

The name it was given, if any.

current

current: boolean

Whether it’s the one shown.

zoomed

zoomed: boolean

Whether only its active pane is shown.

panes

panes: { View }

Its panes, left to right and top to bottom.

active

active: View

The pane keys go to while it’s shown.

See View.

Tabs

list

list: () -> { TabInfo }

The shown project’s tabs, in order.

current

current: () -> TabInfo

new

new: (buffer: Buffer?) -> number

Opens a tab after the shown one, with a pane showing buffer (or an empty buffer), and shows it. Returns its id.

switch

switch: (id: number) -> boolean

Shows tab id, of whichever project, and its project. False if there’s no such tab.

close

close: (id: number) -> boolean

Closes tab id and its panes. The last tab can’t be closed; false then.

rename

rename: (id: number, name: string?) -> boolean

Names tab id; nil or “” names it after what it shows again.

set_zoomed

set_zoomed: (zoomed: boolean) -> ()

Shows only the active pane of the shown tab, or all of them again.

layout

layout: (id: number?) -> any

How tab id (the shown one by default) lays out its panes, as a PaneLayout, with sizes adding up to 1 in each split.

set_layout

set_layout: (layout: any, id: number?) -> ()

Lays tab id’s panes out as layout (a PaneLayout) instead. It arranges the panes the tab has, so it has to hold each of them once; opening and closing panes is view:split and view:close. A split of one pane is that pane; splits nest at most 64 deep.

PaneLayout

A tab’s panes: a pane is its view, a split lays out its children side by side (“row”) or one above another (“column”), sharing the room by sizes, which are relative to each other (equal when left out).

PaneLayout = View | { split: "row" | "column", children: { PaneLayout }, sizes: { number }? }

PaneOpened

A pane was opened, beside from.

view

view: View

See View.

from

from: View

See View.

SessionInfo

A session running on this machine: an editor process of its own.

name

name: string

root

root: string?

The project it was started for.

build

build: string?

The build of greed it runs, as greed --version says it, if it said.

current

current: boolean

Whether it’s this session.

service

service: string?

The service whose owner it runs (its name is the service’s with .service after it), if it’s one.

Sessions

list

list: () -> { SessionInfo }

The sessions running on this machine, by name.

current

current: () -> string?

This session’s name, when the editor runs as one.

build

build: () -> string

Which build of greed this is, as greed --version says it.

fresh

fresh: () -> boolean

Whether the session was started with greed --fresh, to begin without what it had open before.

restoring

restoring: () -> boolean

Whether the session was started with greed --restore, or for an upgrade, to open what it had open before even after it was quit.

remote

remote: () -> boolean

Whether the attached client (or the last one) came over greed ssh; before any attached, whether greed ssh started the session.

attached

attached: () -> boolean

Whether a terminal or window is attached to the session.

program

program: () -> string?

Where the greed program running this editor is, to start greed mcp or greed ctl for this session.

status

status: (name: string) -> ({ [string]: any }?, string?)

What the session name on this machine says of itself, as its status tool gives it (schema, session, attention, agents), asked as an ordinary client, so asking can’t do anything there; or nil and why: it’s gone, its greed has no status, or it didn’t answer in time. It waits, so it works in a command, an event handler or greed.spawn.

start

start: (name: string) -> (boolean?, string?)

Starts the session name on this machine in the background, unless it’s running, and waits until it listens; true, or nil and why it didn’t start. The client stays where it is. A service’s session (NAME.service) works from a folder of its own. It waits, so it works in a command, an event handler or greed.spawn.

switch

switch: (to: { name: string?, path: string?, new: boolean?, host: string?, window: boolean?, back: boolean?, home: boolean? }) -> ()

Sends the attached client to the session name, or to the session for the project path is in (opening it there), starting it if it isn’t running. This session goes on without the client. With new, a new session for path’s project, even when one is running for it. With host, the session is on that machine, reached as greed ssh does. With window, a window client opens it in another window and stays on this session; a terminal goes to it as without. back goes to where the client was before, on whichever machine, and home to the session on the client’s own machine it was on last, or the one name names there; back goes on its own, and home with a name at most.

Json

JSON. Tables with keys 1..n become arrays, other tables objects; an empty table is an object unless it came from array.

encode

encode: (value: any) -> string

value as JSON. Text that isn’t UTF-8, like a program’s binary output, has its broken bytes written as U+FFFD.

decode

decode: (text: string) -> (any, string?)

The value, or nil and why the text isn’t JSON. null becomes nil.

array

array: <T>(items: { T }?) -> { T }

Marks items (or a new table) to encode as an array even when empty.

is_array

is_array: (value: any) -> boolean

Whether value is marked to encode as an array, by array or by decode, so a copy of it can be marked too.

SiktProblem

A mistake or a warning in a sikt program: its words, where it is in the program’s text (from its first byte to just after its last), what might help, and whether it’s only a warning.

SiktProblem = { message: string, at: { from: number, to: number }, help: string?, warning: boolean }

SiktPlace

Where a sikt match is in its text: from its first byte to just after its last, on line (from 1) where it starts.

SiktPlace = { from: number, to: number, line: number }

SiktRow

A match of a sikt program: its captures by name. integer, number, size (bytes), percent and duration (seconds) captures are numbers, the rest text; a capture that didn’t take part is missing.

SiktRow = { [string]: string | number }

SiktProgram

A compiled sikt program, to run as often as needed.

warnings

warnings: { SiktProblem }

What the program probably doesn’t mean, like a part that can never match.

captures

captures: { { name: string, type: string? } }

Its captures, each with its type (“text”, “integer”, “number”, “size”, “percent”, “duration”).

rows

rows: (self: SiktProgram, text: string, opts: { at: boolean?, text: boolean? }?) -> ({ SiktRow }, { SiktPlace }?)

The matches in text, each a row of its captures; with at, also where each is; with text, every capture as the text it matched (“1.5G” rather than its bytes). It runs on the editor’s thread, so for a lot of text use rows_many. An error when matching gives up, on a pattern that takes too many steps.

rows_many

rows_many: (self: SiktProgram, texts: { string }, opts: { at: boolean?, text: boolean? }?) -> ({ { SiktRow } }, { { SiktPlace } }?)

rows for each of texts, run on other threads and waited for like greed.sleep (commands, handlers, greed.spawn). The rows become Luau tables all at once when it’s done, so give it a few hundred texts at a time.

replace

replace: (self: SiktProgram, text: string) -> string

text with each match replaced as the program’s replace says; unchanged without one.

Sikt

sikt: patterns that read like sentences (year: 4 digit "-" month: 2 digit), for reading structure out of text. The language: https://github.com/johnae/sikt/blob/main/docs/language.md

compile

compile: (source: string, opts: { lines: boolean?, nocase: boolean?, modules: { [string]: string }? }?) -> (SiktProgram?, string?)

Compiles source, a sikt program, or gives nil and what’s wrong. It matches each line on its own unless lines is false; nocase ignores case; modules holds rule files by name for use "name".

check

check: (source: string, opts: { lines: boolean?, nocase: boolean?, modules: { [string]: string }? }?) -> { SiktProblem }

What’s wrong with source (compiled as compile would) and what it probably doesn’t mean, each with where it is: to mark them in a program as it’s written.

Control

Needs the “control” capability (and serve_ide “net” too).

reply

reply: (id: number, result: any, message: string?) -> ()

Answers request id with result, or with an error message. Every request needs exactly one answer.

send

send: (connection: number?, method: string, params: any) -> boolean

Sends a notification of method with params to the session socket connection a request came on (its connection), e.g. MCP’s “notifications/tools/list_changed”. False if that connection has closed.

serve_ide

serve_ide: (folders: { string }, lock_dir: string?) -> number

Lets Claude Code find this editor with /ide: listens on a localhost WebSocket and writes a lock file naming folders as open, in lock_dir (default ~/.claude/ide). Its requests come with client “ide”. Returns the port; calling it again replaces the connection.

ide_folders

ide_folders: (folders: { string }) -> ()

Names folders as open in the lock file serve_ide wrote, as when an agent’s workspace is added; Claude Code started from now on sees them, and those connected stay connected.

notify

notify: (method: string, params: any) -> ()

Sends a notification, e.g. “selection_changed”, to Claude Code.

SshAgentUse

A program in a session greed ssh started asks to sign with one of your ssh keys, through the client relaying your agent. Answer with greed.ssh_agent.answer; with no answer, or no handler, it may not.

id

id: number

The request, for greed.ssh_agent.answer.

client

client: number

The client relaying your agent, which handlers run as.

host

host: string?

The machine that client is on, if known.

SshAgent

Needs the “ssh-agent” capability.

answer

answer: (id: number, allowed: boolean) -> boolean

Answers “ssh_agent.use” request id: whether the program may sign with your key. False if it no longer waits (answered already, or it gave up).

ProfileRow

One row of greed.profile.stop(): what a plugin (nil for the editor itself) spent doing one thing, in all and at most once, in milliseconds.

ProfileRow = { plugin: string?, what: string, ms: number, longest: number, runs: number }

DebugLine

One line greed.debug.lines() returns: id counts up, at is milliseconds since the editor started, plugin is set for a plugin’s own lines.

DebugLine = { id: number, at: number, topic: string, plugin: string?, text: string }

Debug

Debug lines: what the editor, its clients and plugins say they’re doing, kept while their topic is on. Topics: keys, runs, frames, rpc, jobs, client, plugins (or plugin:NAME for one). Off, a topic costs next to nothing.

log

log: (...any) -> ()

Keeps a line from this plugin, its parts joined by spaces, when plugins or plugin:NAME is on; otherwise does nothing. Check on() first when making the parts costs something.

on

on: (name: string?) -> boolean

Whether this plugin’s lines are kept, or with name, whether that topic (or plugin:NAME) is on.

set

set: (name: string, on: boolean) -> ()

Turns a topic, plugin:NAME, or all on or off.

switch

switch: (words: string) -> ()

Switches topics as words say, with spaces between: a name turns it on, -name off, off everything, as :debug takes them.

off

off: () -> ()

Turns every topic off.

enabled

enabled: () -> { string }

What’s on.

topics

topics: () -> { string }

Every topic’s name.

lines

lines: (opts: { after: number?, limit: number?, topic: string?, plugin: string? }?) -> { DebugLine }

The lines kept, oldest first: those after the id after, of one topic or plugin, at most the last limit (1000).

clear

clear: () -> ()

Forgets the lines kept so far.

ClientAttached

A client attached, e.g. greed FILE in a session that was running. Handlers run as that client.

client

client: number

The client’s id.

path

path: string?

The file or folder it asked to open, if any.

terminal

terminal: boolean

Whether it asked for a terminal, e.g. greed ssh HOST --terminal.

shell

shell: boolean

Whether it asked for the project’s greed shell, e.g. greed --shell.

remote

remote: boolean

Whether it came over greed ssh.

ClientDetached

A client went; the session goes on. Handlers run as that client, just before it’s gone.

client

client: number

ClientPaste

Text pasted into the client from the system clipboard: a terminal’s paste, or a window’s paste keys (ctrl-shift-v, shift-insert, cmd-v). The core plugin puts it at the cursors.

client

client: number

The client it was pasted into, which handlers run as.

text

text: string

ViewClosed

A view was closed. Its handle no longer works, but its id can be compared with view:id().

view

view: number

MouseEvent

What the mouse did, and what was under it.

client

client: number

The client whose mouse it was, which handlers run as.

kind

kind: "press" | "release" | "drag" | "move" | "scroll"

button

button: ("left" | "middle" | "right")?

For a press, release or drag.

dir

dir: ("up" | "down" | "left" | "right")?

For a scroll.

col

col: number

The screen cell, from the top left.

row

row: number

ctrl

ctrl: boolean

alt

alt: boolean

shift

shift: boolean

view

view: View?

The view under it, if any.

See View.

pos

pos: number?

The place in the view’s buffer under it: the character there, or the end of the line past it. Over a mark’s text, where the mark starts.

action

action: string?

The action of the mark whose text it’s over, or of the status line segment (with no view), if that has one.

x

x: number?

The cell in the view’s text, from its top left, right of the gutter.

y

y: number?

tab

tab: number?

The tab whose name it’s over, in the tab line.

border

border: ("top" | "bottom" | "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right")?

On a floating view’s border (with view set), which part: “top” (the title’s), “bottom”, “left”, “right”, or a corner like “bottom-right”.

edge

edge: ("left" | "right" | "down")?

On the line between a pane or panel (view) and its neighbor, the side of view it’s on: “right” or “down” for panes, the side by the main view for panels. Dragging it resizes view with resize.

ViewResized

A view was drawn for a client with room for a different number of rows or columns of text than before. Handlers run as that client.

client

client: number

view

view: View

See View.

rows

rows: number

cols

cols: number

ViewScrolled

A view was drawn for a client starting at a different line than before. What a handler changes shows in the same frame, so a view can scroll another along with it. Handlers run as that client.

client

client: number

view

view: View

See View.

line

line: number

The 0-based line now at the top.

SelectionChanged

A view’s selection changed for a client, or it shows another buffer, since the last frame: told once a frame however many changes there were, whatever made them (keys, the mouse, undo, a plugin or an agent). Handlers run as that client.

client

client: number

view

view: View

See View.

ViewFocused

Another view has a client’s focus. from had it before; nil when it was closed. Handlers run as that client.

client

client: number

view

view: View

See View.

from

from: View?

See View.

moved

moved: boolean

The focus was moved under the client rather than by it: what it had focused went out of sight by another client’s doing (another tab or project shown, a pane closed), or it followed the others again. Its half-typed keys were dropped.

OptionChanged

An option was set, with greed.option.set or :set.

name

name: string

value

value: OptionValue

Its value now, as the client it was set for has it.

See OptionValue.

client

client: number?

The client it was set for, when one got a value of its own.

FileChanged

A file watched with greed.fs.watch was written, created or removed.

path

path: string

PluginLoaded

A plugin was loaded (or reloaded) and its entry file ran.

name

name: string

dir

dir: string?

Its folder, for plugins loaded from one.

PluginUnloaded

A plugin was unloaded, and everything it registered removed.

name

name: string

CommandRun

client

client: number

The client it runs for, which handlers run as.

name

name: string

The command about to run.

keys

keys: string?

The keys that ran it, when keys did, e.g. “g g”.

count

count: number?

The number typed before the keys.

KeysPending

client

client: number

The client typing them, which handlers run as.

keys

keys: string

The unfinished key sequence, e.g. “space”; “” once it’s finished.

StatusSegment

A piece of the status line: plain text, or text with a style.

text

text: string

style

style: string?

A style name, e.g. “ui.statusline.mode”, drawn over “ui.statusline”.

action

action: string?

A command a click on it runs.

StatusContext

What a status line function gets, for the main view.

view

view: View

See View.

buffer

buffer: Buffer

See Buffer.

mode

mode: string

message

message: string?

The latest message or error, if there is one to show.

width

width: number

The width of the screen in cells.

StatusParts

Segments for each side. The space between is padded; if the line is too long, the last segment on the left keeps only its end.

left

left: { StatusSegment }?
right: { StatusSegment }?

Clipboard

Copied text. Each copy holds one piece per selection it came from, so pasting into the same number of selections puts each piece back.

set

set: (pieces: string | { string }) -> ()

get

get: () -> { string }?

The latest copy.

history

history: () -> { { string } }

Recent copies, newest first.

image

image: () -> string?

The image on the system clipboard of the client acting now, as PNG bytes, read on that client’s own machine (so with greed ssh, your laptop’s); nil when there’s none or the client can’t read it. Waits like greed.sleep.

ClientInfo

A client attached to the editor: a terminal or window, on this machine or over greed ssh.

id

id: number

name

name: string

Its kind and machine, like “tui@laptop”; a client coming back with the same name gets its cursors, focus and mode back.

kind

kind: string

“tui”, “gui”, “headless” (the editor’s own, with nothing attached) or “test”.

remote

remote: boolean

Whether it came over greed ssh.

size

size: { width: number, height: number }?

Its screen in cells, once it has said.

layout

layout: "follow" | "independent"

“follow”: it shows the project, tab and panes the other followers do, with its own focus and zoom. “independent”: a layout of its own.

status_line

status_line: boolean

Whether it shows the status line (set_status_line).

scaled_text

scaled_text: boolean

Whether it draws scaled text (a mark’s scale) bigger: the window does, and so does a terminal with kitty’s text sizing; others draw it at its usual size, in the room it would take.

color

color: number

Which of the peer colors (1 to 6) its cursors show in for the other clients, as ui.cursor.peer.N.

person

person: string

Who it belongs to: “owner”, the session’s owner, for now.

Client

The clients you see the editor through. Commands, keys and event handlers act for one client at a time: the one that typed, clicked or ran them, or the one an event is about.

current

current: () -> ClientInfo

The client the running code acts for.

id

id: () -> number

The id of the client the running code acts for: current().id, without building the rest. For keeping what each client has open apart, like a picker of its own.

list

list: () -> { ClientInfo }

Every client, in the order they attached.

notify

notify: (title: string, body: string?, client: number?) -> ()

Sends a notification to your desktop through a client: client (an id from list), or the one used last; a terminal shows it with its notification escape (OSC 9, or OSC 777 in foot and urxvt) and a bell, while it isn’t focused. Without a client attached it goes nowhere.

home

home: (client: number) -> ({ [string]: any }?, string?)

What the hub on the machine client (an id from list) runs on says, as its status gives it (with machine and machines), for a session on another machine to show what you have where you are; the client, attached over greed ssh, asks it as an ordinary client, so nothing there can be done through it. Or nil and why: the client has no hub to ask (a client here, an older greed) or didn’t answer in time. It waits, so it works in a command, an event handler or greed.spawn.

open

open: (link: string, client: number?) -> (boolean?, string?)

Opens the web or mail link link on the machine of client (the acting one by default), where you are, with its opener: true, or nil and why, like a client that can’t (only one attached over greed ssh can). It waits, so it works in a command, an event handler or greed.spawn.

set_layout

set_layout: (layout: "follow" | "independent", client: number?) -> boolean

Lays a client (the acting one by default) out on its own, “independent”, starting from a copy of the tabs, panes and panels it had, with views of its own; or has it “follow” the others again, closing those views (their buffers stay). Returns whether it changed.

set_status_line

set_status_line: (shown: boolean, client: number?) -> ()

Shows or hides the status line of a client (the acting one by default), its row going to the text while hidden, as slides do while a talk is shown: only on that client’s screen. Errors without such a client.

Diagnostic

A problem a language server found.

from

from: number

to

to: number

severity

severity: number

1 error, 2 warning, 3 information, 4 hint.

message

message: string

source

source: string?

server

server: number?

The id of the server that reported it.

code

code: any?

What the server knows it by, its code and data, to send back with it when asking it for fixes.

data

data: any?

LspError

The error a language server answered a request with.

code

code: number

message

message: string

data

data: any?

LspPosition

A position as language servers count it.

line

line: number

character

character: number

Lsp

Language servers. A language has a main server and may have others that run beside it, like eslint beside TypeScript’s; each runs per project root, started the first time a file that needs it is open, and started again if it stops. A buffer has every one of its language’s that runs for it, the main one first: functions taking a buffer use its first unless given a server’s id (servers_of).

server

server: (spec: { language: string, name: string?, when: { string }?, command: { string }?, commands: { { string } }?, root_markers: { string }?, reads_only: boolean?, settings: { [string]: any }?, folder_setting: string?, init_options: { [string]: any }?, only: { string }?, except: { string }? }) -> ()

Sets a server for a language, e.g. { language = "rust", command = { "rust-analyzer" }, root_markers = { "Cargo.toml" } }. Without name it’s the language’s main server; with one, a server that runs beside it, set and replaced by its name. With commands, the first one whose program is installed runs, when a file of the language first opens; with none installed, nothing does. A server runs in the topmost folder with one of root_markers inside the file’s project, or the project’s root without one. With when, it runs only for files under a folder that has one of those files, in the nearest such folder. With reads_only, the server only reads the project’s files, never running its code, so it starts in a project nobody trusted (see trust). settings are the server’s settings, sent once it’s initialized and what it gets when it asks for a section; init_options goes with initialize. A running server keeps the ones it started with until it’s restarted. folder_setting names a setting that gets the folder the server runs in, as { uri, name }, for a server that reads it from its settings, as eslint’s does with “workspaceFolder”. only and except name the features it’s used for, like “hover” or “format”, for plugins that pick one of a buffer’s servers for a feature: only those, when given, and never those in except.

remove

remove: (language: string, name: string?) -> ()

Stops starting the language’s server called name, or all of its servers without one; one running keeps running.

restart

restart: (language: string?) -> number

Stops the servers running for language (every language without one) and starts them again, as after they got stuck. Returns how many were running. Needs “proc”.

trust

trust: (folders: { string }?) -> ()

Lets servers start only in folders and the folders inside them, as a server runs a project’s code (a build script, a config file); nil lets them start anywhere. A server set up with reads_only starts anywhere. One held back starts once its folder is trusted. Needs “proc”.

waits

waits: (buffer: Buffer) -> boolean

Whether the buffer’s server is held back until its folder is trusted (trust): one is set up for its language and installed, runs the project’s code, and may not start where it would run.

servers

servers: () -> { [string]: { { string } } }

The commands set for each language’s main server, by language.

running

running: () -> { LspServer }

The servers running now, by language, name and root.

failures

failures: () -> { LspFailure }

The servers given up on, as they couldn’t start or kept stopping, by language, name and root; not tried again until their language is set up again or :lsp-restart. Not those that aren’t installed.

servers_of

servers_of: (buffer: Buffer) -> { LspBufferServer }

The buffer’s running servers, its language’s main one first and then the others in the order they were set up.

root

root: (buffer: Buffer) -> string?

The folder the buffer’s first server runs in, or would: nil without a file or a server set for its language.

request

request: (buffer: Buffer, method: string, params: any, server: number?) -> (any, LspError?)

Sends a request to server, one of the buffer’s (its first without one), and waits for the answer. Returns the result, or nil and the error; a server that stops before answering gives the error “the language server stopped”. Works in commands and event handlers. “workspace/executeCommand” needs “proc”, since a server’s commands can do anything.

uri

uri: (buffer: Buffer) -> string

The buffer’s file as a URI, for request parameters.

path

path: (uri: string) -> string?

The file path in a file:// URI.

position

position: (buffer: Buffer, pos: number, server: number?) -> LspPosition

Byte offset pos as server (the buffer’s first without one) counts positions. server may be any running server, like the one that named a place in this file before the file had a server of its own.

offset

offset: (buffer: Buffer, position: LspPosition, server: number?) -> number

The byte offset of a position as server (the buffer’s first without one) counts it; any running server, as for position.

diagnostics

diagnostics: (buffer: Buffer) -> { Diagnostic }

The buffer’s latest diagnostics from all its servers, where they are now: they move with edits. They are marks in the buffer’s “diagnostics” namespace, with { severity, message, source, server } as their data.

problems

problems: () -> { LspProblem }

Every file’s latest problems, including files that aren’t open, with ranges as the server counts positions. Those in open files are where they are now.

capabilities

capabilities: (buffer: Buffer, server: number?) -> any

What server (the buffer’s first without one) said it can do (its ServerCapabilities), or nil without a running server.

on_request

on_request: (method: string, handler: (params: any, server: number) -> any) -> ()

Answers requests of method from servers, e.g. “workspace/applyEdit”, with what handler returns, given the asking server’s id. It can wait, e.g. to ask you; the server gets the answer when it returns.

on_notification

on_notification: (method: string, handler: (params: any, language: string, root: string, server: number, name: string) -> ()) -> ()

Hears notifications of method from servers that the editor doesn’t deal with itself, e.g. “$/progress”, with the language, root, id and name of the server that sent it.

LspBufferServer

One of a buffer’s servers (servers_of): its id, its name (its language’s for the main one) and what it can do.

id

id: number

name

name: string

capabilities

capabilities: any

only

only: { string }

The features it’s used for when there are any, and those it isn’t, as it was set up.

except

except: { string }

LspFailure

A language server given up on (failures).

language

language: string

name

name: string

Its name: its language’s for the main one.

root

root: string

The folder it ran in.

said

said: { string }

Why: the last lines it wrote to stderr, or why it couldn’t start.

LspServer

A language server that’s running.

id

id: number

language

language: string

name

name: string

Its name: its language’s for the main one.

root

root: string

The folder it runs in.

command

command: { string }

ready

ready: boolean

Whether it has answered initialize.

stderr

stderr: { string }

The last lines it wrote to stderr.

LspProblem

uri

uri: string

range

range: { start: LspPosition, ["end"]: LspPosition }

severity

severity: number

message

message: string

source

source: string?

DiagnosticsChanged

buffer

buffer: Buffer

See Buffer.

Message

What the status line is about to show. What a handler echoes shows instead, and isn’t told again.

text

text: string

error

error: boolean

Something failed: an error, or a command that refused.

ModeChanged

A client’s mode changed. Handlers run as that client.

client

client: number

from

from: string

to

to: string

DirEntry

name

name: string

dir

dir: boolean

FileInfo

kind

kind: "file" | "dir" | "other"

size

size: number

Size in bytes; 0 for a directory.

mode

mode: number

Its permission bits, like 420 (644 in octal, as string.format("%o", mode) shows).

modified

modified: number?

When it last changed, in seconds since 1970, where the system says.

Hash

SHA-256 digests as lowercase hex, for checking a download or telling whether some text changed, and random bytes for one-time codes.

sha256

sha256: (data: string) -> string

The digest of data.

random

random: (count: number) -> string

count (1 to 1024) bytes from the system’s random source, as lowercase hex: for a one-time code or a sign-in’s PKCE verifier.

sha256_file

sha256_file: (path: string) -> (string?, string?)

The digest of the file at path, read in pieces, or nil and why. Needs “fs.read”.

Compare

Comparing values the way filters do, the same in a view’s filter (level>=warn) and a table’s where (RESTARTS>0): numbers as numbers, with sizes (512Mi, 1.5G, 250m), % and durations (3d16h, 500ms); log levels in their order; anything else as text without minding case.

number

number: (text: string, durations: boolean?) -> number?

text as a number: its first word, with a size suffix, a % or a duration in seconds; with durations, a lone m is minutes (an AGE column) rather than thousandths (kubectl’s CPU). Nil when it isn’t one.

test

test: (have: string, op: string, want: string, durations: boolean?) -> boolean

Whether have passes op (=, !=, ~ has it in it, !~, <, <=, >, >=) against want. durations defaults to whether want is one.

order

order: (a: string, b: string, durations: boolean?) -> number

-1, 0 or 1 as a comes before, with or after b: numbers first, then log levels, then text.

is_duration

is_duration: (text: string) -> boolean

Whether text is a duration with a unit only durations have (45s, 2h, 3d), so a column of them takes 12m as minutes.

find

find: (text: string) -> (number?, number?, string?)

The first operator in text: where it starts and ends (as string.find gives) and the operator. At one place, the longest (<=, not <).

QueryRow

A row for greed.query.run: its text for words, its fields’ values by name (a string or a list), the flags it has, its name (for in:NAME) and the row it’s in (parent, its index in the list).

QueryRow = { text: string?, fields: { [string]: string | { string } }?, flags: { string }?, name: string?, parent: number? }

QuerySchema

What a query’s fields and flags mean, for greed.query.run: each field’s kind by name (“text”, “exact”, “value” or “date”), each flag’s by name (“row”, kept on the rows, or “computed”, worked out by the source, so rows that depend on it are a maybe), whether words match anywhere in the text rather than as whole words, whether fields it doesn’t name are loose (any field compares as a value, from each row’s own), whether words mind case, and the field holding the places a row is in besides its parent (a mail’s labels), which in:NAME matches too.

QuerySchema = { fields: { [string]: string }?, flags: { [string]: string }?, anywhere: boolean?, loose: boolean?, case: boolean?, places: string? }

Query

Running a query core.query parsed, with its dates read into the days they cover (from and to on a date field’s term).

run

run: (query: any, rows: { QueryRow }, schema: QuerySchema) -> ({ number }?, { number }?, string?)

The rows of rows that match query (all of them, for nil), by their index and in their order, and those of them that only might, where it depends on a computed flag. Nil and why for a query that can’t run, like a regex that doesn’t compile.

fold

fold: (text: string) -> string

text as queries compare words and values when case doesn’t matter: in lower case, with accents taken off (“Café” as “cafe”).

IndexItem

An item for index:write: its key, unique in the index, the parent key of the item it’s in, its name (for in:NAME), its text for words, its fields’ values by name (a string or a list) and its flags. words names the fields searched by word (text fields); without it, every field is, which costs more to write.

IndexItem = { key: string, parent: string?, name: string?, text: string?, fields: { [string]: string | { string } }?, flags: { string }?, words: { string }? }

Index

An index on SQLite, from greed.index.open or greed.index.writer, that queries core.query parsed run over. Its methods run on another thread and wait like greed.sleep, so only in commands, event handlers and greed.spawn.

search: (self: Index, query: any, schema: QuerySchema, view: { sort: { { field: string, descending: boolean } }?, limit: number? }?) -> ({ string }?, { string }?, string?)

The keys of the items matching query (every item, for nil), as schema says what its fields and flags mean, sorted and cut as view says; and of those, the ones that only might match, where it depends on a computed flag (then nothing is cut). Nil and why for a query that can’t run.

items

items: (self: Index, keys: { string }) -> ({ IndexItem }?, string?)

The items with keys, as they were put in (without words), in that order; keys it doesn’t hold are left out. For showing what search found. Nil and why when it can’t read them.

write

write: (self: Index, items: { IndexItem }) -> (boolean?, string?)

Puts items in, in one go, each in place of the one with its key, with what its text mentions in its field ref (see refs); an index from open can’t be written. True, or nil and why.

remove

remove: (self: Index, keys: { string }) -> (boolean?, string?)

Takes the items with keys out. True, or nil and why.

count

count: (self: Index) -> (number?, string?)

How many items it holds, or nil and why.

IndexModule

Indexes on SQLite: one file that one program writes and any number read.

open

open: (path: string) -> (Index?, string?)

The index at path to read, while another program may write it; nil and why, as when it isn’t there. Needs “fs.read”.

writer

writer: (path: string) -> (Index?, string?)

The index at path to write, made if it isn’t there, and made again when another Greed’s version of it is there. Needs “fs.write”.

refs

refs: (text: string) -> { string }

What text mentions that lives elsewhere, sorted, as an index keeps it in each item’s field ref: a Jira ticket’s key, group/repo#12 and repo#12 for an issue, !12 for a merge request, a commit’s hash, and any link’s host, path and query. An index also counts bare PLAT-9 or repo!3 once a link has shown what they are; this only reads links.

TextMatch

A match of a regex in some text, from greed.text.matches.

TextMatch = { from: number, to: number, text: string, groups: { string | false } }

Text

Reading lines of text as Greed does, so plugins read them the same way.

shape

shape: (line: string, items: boolean?) -> (number?, string?)

How far line is indented and the key it starts with (name: or "name":), as YAML, indented JSON and kubectl describe nest; nil for a blank line. With items, a list item’s - counts as indent, so - name: x is a key name two further in.

width

width: (text: string, tab_width: number?) -> number

How many cells text takes on screen from a line’s start, as Greed draws it: wide characters (CJK, most emoji) take two, a tab reaches the next stop, tab_width (default 4) apart.

matches

matches: (text: string, pattern: string, limit: number?) -> ({ TextMatch }?, string?)

The matches of the regex pattern in text, first to last (at most limit): where each starts and ends, as string.find says it, its text, and its groups by number (false for one that took no part). Nil and why for a bad pattern. Searches and filters on a buffer go through Buffer.find.

Fs

Reading and writing the file system. Failures return nil and a message. A relative path goes from the shown project’s root, and ~ is your home folder.

list

list: (dir: string, opts: { hidden: boolean?, ignored: boolean? }?) -> ({ DirEntry }?, string?)

The entries directly in dir, folders first, then by name. Hidden entries and ones .gitignore excludes are left out unless asked for.

read

read: (path: string, limit: number?) -> (string?, string?)

The file’s text, or its first limit bytes.

read_bytes

read_bytes: (path: string) -> (string?, string?)

The file’s bytes as they are, for a file that isn’t text, like an image.

stat

stat: (path: string) -> (FileInfo?, string?)

What’s at path; nil if nothing is, and nil and why when it can’t tell, as when a folder above it can’t be read.

write

write: (path: string, text: string, opts: { private: boolean?, background: boolean? }?) -> (boolean?, string?)

Replaces the file’s contents with text, creating it and its folders if needed. It’s written whole or not at all. With private, only you can read it (mode 0600), and folders made for it are only yours. With background, it’s written on another thread and the caller waits like greed.sleep (commands, handlers, greed.spawn), so a slow disk never holds the editor up.

mkdir

mkdir: (path: string) -> (boolean?, string?)

Makes the folder at path and any missing folders above it. Needs “fs.write”.

remove

remove: (path: string, opts: { recursive: boolean? }?) -> (boolean?, string?)

Removes the file, link or empty folder at path; with recursive, a folder and everything in it. Nothing being there counts as removed. It refuses (an error) the root, your home folder, a path with .. and a folder holding Greed’s approvals or secrets. Needs “fs.write”.

rename

rename: (from: string, to: string) -> (boolean?, string?)

Moves or renames from to to, replacing a file there. It refuses what remove does. Needs “fs.write”.

copy

copy: (from: string, to: string) -> (boolean?, string?)

Copies the file from to to, creating its folders. Needs “fs.read” and “fs.write”.

watch

watch: (path: string) -> ()

Watches the file at path: whenever it changes, from inside the editor or out, plugins hear “file.changed”. It needn’t exist yet.

cwd

cwd: () -> string

The directory Greed was started in.

dirs

dirs: () -> { home: string?, config: string?, cache: string?, data: string?, temp: string?, brought: string? }

Your home folder, Greed’s config folder (where init.luau and plugins/ were read from), its cache folder, its data folder (where plugins made in the editor go when the config can’t be written), the system’s folder for temporary files and, on the far end of greed ssh, the copy of your config it brought.

grep

grep: (
	pattern: string,
	dir: string?,
	opts: { hidden: boolean?, ignored: boolean?, limit: number? }?
) -> ({ GrepLine }?, string?)

The lines matching the regex pattern in the text files under dir (default: the current directory), sorted by path and line. It searches in the background and waits like greed.sleep (commands, handlers, greed.spawn). Hidden and ignored files are skipped unless asked for; limit (default 10000) caps the lines returned. A bad pattern gives nil and why.

scan

scan: (dir: string, opts: { ext: string?, read: boolean?, hidden: boolean?, ignored: boolean? }?) -> { ScannedFile }

The files under dir, sorted by path (from dir), each with its size and when it was last written (seconds since 1970), and its text with read (not for binary or very big files). Only files ending .ext with ext; hidden and ignored files are skipped unless asked for. It walks in the background and waits like greed.sleep, so an index of many files can see what changed without holding the editor up.

ScannedFile

A file greed.fs.scan found.

ScannedFile = { path: string, size: number, modified: number, text: string? }

GrepLine

A line greed.fs.grep found.

path

path: string

Relative to the directory searched.

line

line: number

0-based.

text

text: string

The line, without its line break.

matches

matches: { { from: number, to: number } }

Byte offsets of the matches in text.

PluginCheck

What greed.plugin.check found. types.skipped says why types weren’t checked; tests.error why the tests couldn’t run.

types

types: { ok: boolean?, output: string?, skipped: string? }

tests

tests: { passed: number?, failed: { { file: string, name: string, message: string } }?, error: string? }

warnings

warnings: { string }

What looks wrong once it’s loaded with the others: a command it replaces from another plugin, keys bound to commands that don’t exist.

Plugins

list

list: () -> { string }

The names of the loaded plugins, sorted.

unload

unload: (name: string) -> ()

Removes a plugin and everything it registered: commands, keys, options and event handlers. Fails while another loaded plugin requires it. To turn off a default plugin, call this from your config.

load

load: (dir: string, name: string?) -> string

Loads (or reloads) the plugin in dir and returns its name. With name, a folder without a plugin.toml loads too, with init.luau as its entry.

dirs

dirs: () -> { [string]: string }

The folder of each plugin loaded from one, by name.

check

check: (dir: string) -> PluginCheck

Checks the plugin in dir without loading it: strict types against Greed’s API (if luau-analyze is installed), then its tests with the loaded plugins. Waits, like greed.sleep, while it runs. A plugin that needs approving is tested with only what you approved for it, so what needs more fails with “needs approval”, through the plugins it calls and the commands it runs too.

describe

describe: (dir: string) -> PluginInfo

What the plugin in dir is and asks for, from its plugin.toml.

pending

pending: () -> { PluginInfo }

The plugins waiting until what they use is approved.

approve

approve: (dir: string) -> string

Approves what the plugin in dir declares, loads it, and loads the plugins that waited for it. Returns its name. Fails when a plugin without “plugins” started what runs: approving is yours to do.

caller

caller: () -> string?

The plugin whose code called yours: the innermost other plugin on the stack, or the one whose command, handler or task is running; nil if none but yours.

started_within

started_within: (capability: string) -> boolean

Whether everything that started the code running now may use capability: you (keys, the command line, your config), or plugins that have it. A vouch doesn’t hide what started it. For actions only you should take, like accepting a review.

within

within: <A..., R...>(name: string?, f: (A...) -> R..., A...) -> R...

Runs f with ... within the limit of the plugin name too, as if it had started it: for running what a plugin registered (a formatter, a runner, a source) later, from your plugin, so it can do no more than its plugin may. Config and unknown names add nothing. It can wait.

cleanup

cleanup: (remove: () -> ()) -> string

Runs remove when the plugin whose code called yours (see caller) is unloaded or reloaded, so what it added to your registry goes with it; with no other caller, when yours is, for your own cleanup. Returns that plugin’s name.

handler

handler: <A..., R...>(f: (A...) -> R...) -> (A...) -> R...

For registries of handlers, like a service’s: f, a function of the plugin whose code called yours (see caller), wrapped to run as that plugin’s own, as its event handlers do: only its capabilities count, whoever calls it later. A function of any other plugin is an error, so no plugin gets another’s capabilities through it; with no plugin calling (config, tests), f as it is.

PluginInfo

A plugin, as greed.plugin.describe tells it, for a review.

name

name: string

dir

dir: string

requires

requires: { string }

capabilities

capabilities: { { name: string, what: string } }

What it declares, each with what it lets the plugin do in words.

missing

missing: { string }

The capabilities not approved yet; empty when it may load.

Style

How text looks. Colors are “red”, “bright-blue” and the other 16 terminal colors, “default”, or “#rrggbb”. Fields left out leave whatever is underneath, so styles layer.

fg

fg: string?

bg

bg: string?

underline

underline: (boolean | string)?

true, or “line”, “curl”, “dotted”, “dashed” or “double”.

underline_color

underline_color: string?

bold

bold: boolean?

italic

italic: boolean?

dim

dim: boolean?

reverse

reverse: boolean?

strikethrough

strikethrough: boolean?

rounded

rounded: boolean?

For floats (ui.float): rounded corners, in the window drawn as an outline instead of box lines, in a terminal as ╭╮╰╯. The built-in themes set it in the gui part, so terminals draw square boxes.

shadow

shadow: boolean?

For floats in the window: a soft shadow under them.

badge

badge: boolean?

For text in the window: its background as a badge, a box with rounded corners a little inside its cells, as motion hints have.

hover

hover: boolean?

For something pressable in the window, like a button: lit up while the mouse is over it, drawn by the window itself. Terminals don’t.

checkbox

checkbox: ("empty" | "checked" | "choice" | "chosen")?

In the window, drawn as a control over the cells of its text: a checkbox (“empty” or “checked”, for todos) or a choice (“choice” or “chosen”). Terminals show the text.

font

font: string?

The window’s font for the text: “mono”, the grid’s (gui-font), “prose”, a proportional one (gui-font-prose) fitted into the same cells, or a family’s name, like “Monaspace Radon”, drawn in the grid’s cells, or in the grid’s font when it isn’t installed. Terminals have only the one.

ThemeEntry

A theme entry: a style for every client, with changes for the terminal (tui) or a graphical client (gui).

tui

tui: Style?

See Style.

gui

gui: Style?

See Style.

Syntax

The tree-sitter queries each language uses: “highlights” for highlighting, “injections” for languages inside others (code blocks in Markdown), and others (“textobjects”, …) that plugins read. The languages plugin sets them from the queries/<language>/<kind>.scm files in plugins and your config.

set_query

set_query: (language: string, kind: string, source: string?) -> ()

Sets the kind query for language, or with nil takes this plugin’s away. Errors if the language’s grammar can’t compile it. The newest one set is used, and unloading a plugin takes its queries away.

query

query: (language: string, kind: string) -> string?

The kind query in use for language: the one set, the one set for the language it shares a grammar with, or for “highlights” and “injections” the one that comes with the grammar.

share_grammar

share_grammar: (language: string, other: string) -> ()

Lets language use the grammar of other, which has one, like Starlark Python’s. It uses other’s queries too, except those set for it.

load_grammar

load_grammar: (language: string, path: string, symbol: string?) -> ()

Loads the grammar for language from a WebAssembly file, like one built with tree-sitter build --wasm, so buffers in it get a syntax tree. symbol is the grammar’s own name when it differs, e.g. “c_sharp” for “c-sharp”; by default the language with “-” as “_”. Queries come separately. Needs “fs.read”.

tags

tags: (dir: string?, opts: { limit: number? }?) -> { FileTags }

What the source files under dir (default: the current directory) define and use, from their syntax trees: the functions and types their “textobjects” query finds and how often each name appears, sorted by path. Hidden and ignored files are skipped; limit (default 10000) caps the files. It parses in the background and waits like greed.sleep. Needs “fs.read”.

FileTags

What one file defines and uses, from greed.syntax.tags.

path

path: string

Relative to the directory searched.

language

language: string

definitions

definitions: { { name: string, kind: "function" | "type", line: number, signature: string } }

Each with its 0-based line and its first line as signature.

references

references: { [string]: number }

How often each name appears in the file.

Theme

What style names look like. Everything on screen has one: “ui.text”, “ui.selection”, “ui.statusline.mode”, “ui.float.border”, “keyword”, “diagnostic.error”, or a name a plugin made up. Names fall back to their parent, so “markup.heading.1” uses “markup.heading” if it has no entry.

set

set: (entries: { [string]: ThemeEntry }) -> ()

Sets entries by name. Each changes only the fields it gives of the theme’s entry underneath, and replaces what was set for that name before.

base

base: (entries: { [string]: ThemeEntry }) -> ()

Replaces the base theme, the entries under those set with set: a theme plugin calls it to switch themes without touching what your config or other plugins set.

get

get: (name: string) -> ThemeEntry?

The entry for exactly name, if there is one.

EventName

The events greed.on and greed.off take; any other name is an error.

EventName =