From f940a04dc89e8427b1561d917126cc571055965a Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Sun, 26 Jan 2025 08:07:32 +0100 Subject: [PATCH] Lua: template.define_slash_command --- plugs/core/Library/Std/Template.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/plugs/core/Library/Std/Template.md b/plugs/core/Library/Std/Template.md index f8e836c6..6e289562 100644 --- a/plugs/core/Library/Std/Template.md +++ b/plugs/core/Library/Std/Template.md @@ -33,4 +33,29 @@ function template.new(template_str) return space_lua.interpolate(template_str, obj) end end + +-- Creates a template-based slash command, keys for def are: +-- name: name of the slash command +-- description: description of the slash command +-- only_contexts: parent AST nodes in which this slash command is available, defaults to everywhere +-- except_contexts: parent AST nodes in which this slash command is not available +-- template: template function to apply +-- insert_at: position to insert the template into +-- match: match string to apply the template to +-- match_regex: match regex to apply the template to +function template.define_slash_command(def) + slash_command.define { + name = def.name, + description = def.description, + onlyContexts = def.only_contexts, + exceptContexts = def.except_contexts, + run = function() + system.invoke_function("template.applySnippetTemplate", def.template(), { + insertAt = def.insert_at, + match = def.match, + matchRegex = def.match_regex + }) + end + } +end ```