---@diagnostic disable: undefined-global local events = require('luasnip.util.events') local fromglob = function(pattern, opts) local choices = {} for _, path in ipairs(vim.fn.glob(pattern, false, true, false)) do choices[#choices + 1] = f(function(_, _, uargs) return vim.fn.readfile(uargs) end, {}, { user_args = { path } }) end return sn(nil, { c(1, choices, opts) }) end local commentwrap = function(opts) return vim.tbl_extend('error', opts or {}, { callbacks = { [-1] = { [events.leave] = function(node) local start_ln = node:get_buf_position()[1] + 1 local end_ln = start_ln + #node:get_text() - 1 require('vim._comment').toggle_lines(start_ln, end_ln) end, }, }, }) end return { -- mini symbols s('check', t([[✔]])), s('cross', t([[✖]])), s('...', t([[…]])), s('->', t([[➞ ]])), s( 'memail', c(1, { t([[robert@gnzler.de]]), t([[robert@gnzler.io]]), }) ), s('mename', t([[Robert Günzler]])), s('date', exec([[date --rfc-email]])), s('mfg', t([[Mit freundlichen Grüßen]])), s('sehr', t([[Sehr geehrte Damen und Herren]])), s('sign', t([[ - Robert]])), s( 'today', f(function() return os.date('%Y-%m-%d') end, {}) ), s( 'now', f(function() return os.date('%Y-%m-%dT%H:%M:%SZ') end, {}) ), s( { trig = 'license' }, d(1, function() local pattern = vim.fn.stdpath('config') .. '/snippets/license_*.txt' return fromglob(pattern, { name = 'LICENSE templates' }) end, nil) ), s( { trig = 'spdx' }, d(1, function() local pattern = vim.fn.stdpath('config') .. '/snippets/spdx_*.txt' return fromglob(pattern, { name = 'SPDX header templates' }) end), commentwrap(nil) ), s( { trig = 'todo' }, isn(1, { c(1, { sn(nil, { i(1, 'TODO') }), sn(nil, { i(1, 'NOTE') }), sn(nil, { i(1, 'XXX') }), }), c(2, { sn(nil, { i(1) }), sn(nil, { t('('), i(1, 'robertgzr'), t(')') }), }), t(': '), i(3, 'your comment here'), }, ''), commentwrap(nil) ), s( { trig = '#!/bin' }, d(1, function() local pattern = vim.fn.stdpath('config') .. '/snippets/sh_*.txt' return fromglob(pattern, { name = 'Shell script template' }) end, {}), { callbacks = { [-1] = { [events.pre_expand] = function() vim.opt_local.filetype = 'sh' end, }, }, } ), }