Replies: 1 comment 6 replies
-
|
Yes, it is possible because entries in Here is an example: local vim_autoload_snippet = function(context)
local buf_name = vim.api.nvim_buf_get_name(context.buf_id)
local autoload_suffix = buf_name:match('autoload[\\/](.+)%.vim$')
if autoload_suffix == nil then return {} end
local autoload_name = autoload_suffix:gsub('[\\/]', '#')
return {
{
prefix = 'fun',
desc = 'Regular function',
body = {
'function! ' .. autoload_name .. '#$1($2) abort',
-- I'd suggest using here `$0` tabstop directly
' $0',
'endfunction',
'',
},
},
}
end
local minisnippets = require('mini.snippets')
minisnippets.setup({
snippets = {
-- Other snippet loaders go here
vim_autoload_snippet,
},
}) |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Contributing guidelines
Module(s)
mini.snippets
Question
Is it possible to run a Lua function while expanding a snippet to achieve dynamic behaviour? E.g., I want to do something like this:
{ prefix = "fun", desc = "Regular function", body = { function() return "function! " .. autoload_name() .. "($2) abort" end, " $3", "endfunction", "", }, },where
autoload_namewill give the current files "autoload prefix". E.g. it could outputvimtex#foo#bar#$1if I'm inside the fileautoload/vimtex/foo/bar.vim.Notice, if I were to inline the above function, i.e.
{ prefix = "fun", desc = "Regular function", body = { "function! " .. autoload_name() .. "($2) abort" " $3", "endfunction", "", }, },then the snippet expansion will not change when I change the file.
Beta Was this translation helpful? Give feedback.
All reactions