description: APIs to define custom commands and slash commands
APIs to define and patch commands and slash commands.
Registers a command.
Available keys:
name: Name of the commandrun: Callback functioncontexts: AST node context in which this command should be availablepriority: Command priority (how high it appears in the list)key: Windows/Linux key binding (and mac, if not separately defined)mac: Mac-specific key bindinghide: Hide this command from the Command PaletterequireMode: rw or ro — only enable this command in a particular mode (read-write, or read-only)Example:
command.define {
name = "My custom command",
run = function()
editor.flashNotification "Triggered my custom command"
end
}
Equivalent to command.define, but can be used to update the definition of previously defined commands (including built-in ones).
Example:
-- To assign a new key binding and command priority to a built-in command
command.update {
name = "Stats: Show",
key = "Ctrl-Shift-t",
priority = 100
}
-- To disable key bindings of an existing command
command.update {
name = "Navigate: Document Picker",
key = "",
mac = "",
}
Defines a custom slash command.
Supported keys in the spec:
name: name of the commanddescription: Description of the commandrun: The callback function that will be invoked once the command is run.Example:
slashCommand.define {
name = "hello-world",
run = function()
editor.insertAtCursor("Hello |^| world!", false, true)
end
}
Most of the heavy lifting happens in SB itself. These are just wrappers around the config object API.
-- priority: 99
command = command or {}
slashCommand = slashCommand or {}
-- DEPRECATED: old name of API
slashcommand = slashCommand
function command.define(def)
config.set({"commands", def.name}, def)
end
function command.update(newDef)
local def = config.get({"commands", newDef.name}, {})
for k, v in pairs(newDef) do
def[k] = v
end
config.set({"commands", newDef.name}, def)
end
function slashCommand.define(def)
config.set({"slashCommands", def.name}, def)
end