summaryrefslogtreecommitdiff
path: root/nvim/lua/autocommands.lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--nvim/lua/autocommands.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/nvim/lua/autocommands.lua b/nvim/lua/autocommands.lua
index 4a565db..ef7353f 100644
--- a/nvim/lua/autocommands.lua
+++ b/nvim/lua/autocommands.lua
@@ -1,3 +1,30 @@
+local function async_cmd(cmd)
+ local job_id = vim.fn.jobstart(cmd, {
+ on_stdout = function(_, data)
+ for _, line in pairs(data or {}) do
+ print(line)
+ end
+ end,
+ on_stderr = function(_, data)
+ for _, line in pairs(data or {}) do
+ print(line)
+ end
+ end,
+ on_exit = function(_, code)
+ if code ~= 0 then
+ vim.notify(
+ string.format("Команда завершилась с ошибкой (%d)", code),
+ vim.log.levels.ERROR
+ )
+ else
+ vim.notify("OK", vim.log.levels.INFO)
+ end
+ end,
+ })
+
+ return job_id
+end
+
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
pattern = "*.go",
callback = function()
@@ -82,6 +109,14 @@ vim.api.nvim_create_autocmd("BufEnter", {
end,
})
+vim.api.nvim_create_autocmd({ "BufWritePost" }, {
+ pattern = "*.templ",
+ callback = function()
+ local cmd = "templ generate"
+ async_cmd(cmd)
+ end,
+})
+
-- vim.api.nvim_create_autocmd("InsertEnter", {
-- pattern = "*",
-- command = "set norelativenumber",