From 0860db73ae6fd9a6f6347219d820bf026a6b8b91 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Sun, 27 Sep 2026 17:38:39 +0200 Subject: * MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automated-commit-by: dots Signed-off-by: Robert Günzler --- .config/nvim/lua/config/autoall.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .config/nvim/lua/config/autoall.lua (limited to '.config/nvim/lua/config/autoall.lua') diff --git a/.config/nvim/lua/config/autoall.lua b/.config/nvim/lua/config/autoall.lua new file mode 100644 index 0000000..6f36182 --- /dev/null +++ b/.config/nvim/lua/config/autoall.lua @@ -0,0 +1,35 @@ +-- Autocommands for all files opened in nvim +local autocmd = vim.api.nvim_create_autocmd +local autogrp = vim.api.nvim_create_augroup + +-- 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 expand_template = function(name) + require('luasnip').snip_expand(require('config.templates')[name]) + require('luasnip').unlink_current() +end + +autocmd({ 'BufEnter', 'BufNewFile' }, { + pattern = 'deb/DEBIAN/changelog_blobs/*.txt', + group = autogrp('DebianChangelogTemplate', { clear = true }), + callback = function(opt) + if bufempty() then + return expand_template('debian-changelog') + end + end, +}) -- cgit 1.4.1