diff options
| author | Robert Günzler <r@gnzler.io> | 2026-09-27 17:38:39 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2026-09-27 17:38:39 +0200 |
| commit | 0860db73ae6fd9a6f6347219d820bf026a6b8b91 (patch) | |
| tree | 11318c3670d1c32c5aa0bf404c22fba3bf63fc53 /.config/nvim/lua/config/templates.lua | |
| parent | 4e34cbf9673aeaba252e01df554a0d204e83c5e2 (diff) | |
| download | dotfiles-0860db73ae6fd9a6f6347219d820bf026a6b8b91.tar.gz | |
Automated-commit-by: dots Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '.config/nvim/lua/config/templates.lua')
| -rw-r--r-- | .config/nvim/lua/config/templates.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/.config/nvim/lua/config/templates.lua b/.config/nvim/lua/config/templates.lua new file mode 100644 index 0000000..a01efa1 --- /dev/null +++ b/.config/nvim/lua/config/templates.lua @@ -0,0 +1,53 @@ +-- template snippets +require('luasnip').setup_snip_env() +local templates = {} + +-- check if the current buffer is empty +local bufempty = function(bufnr) + bufnr = bufnr or 0 + if vim.api.nvim_buf_get_offset(bufnr, 0) <= 0 then + local handle = io.open(vim.api.nvim_buf_get_name(bufnr)) + if handle == nil then + return true + end + local eof = handle:read(0) + handle:close() + if eof == nil then + return true + end + end + return false +end + +local register_template = function(pattern, snip) + templates[pattern] = snip + + vim.api.nvim_create_autocmd({ 'BufEnter', 'BufNewFile' }, { + pattern = pattern, + group = vim.api.nvim_create_augroup('Template' .. pattern, { clear = true }), + callback = function(opt) + if bufempty() then + require('luasnip').snip_expand(templates[pattern]) + require('luasnip').unlink_current() + end + end, + }) +end + +register_template( + 'deb/DEBIAN/changelog_blobs/*.txt', + s( + 'debian-changelog', + fmt( + [[ +ukp-agent (${VERSION}) unstable; urgency=medium + + * feat: <> +]], + { i(0) }, + { + delimiters = '<>', + } + ) + ) +) |