mirror of
https://github.com/zoriya/auto-save.nvim.git
synced 2025-12-06 06:36:11 +00:00
feat: GH-45 Add events when enabling/disabling the plugin (#46)
This commit is contained in:
@@ -206,6 +206,8 @@ The plugin fires events at various points during its lifecycle which users can h
|
|||||||
|
|
||||||
- `AutoSaveWritePre` Just before a buffer is getting saved
|
- `AutoSaveWritePre` Just before a buffer is getting saved
|
||||||
- `AutoSaveWritePost` Just after a buffer is getting saved
|
- `AutoSaveWritePost` Just after a buffer is getting saved
|
||||||
|
- `AutoSaveEnable` Just after enabling the plugin
|
||||||
|
- `AutoSaveDisable` Just after disabling the plugin
|
||||||
|
|
||||||
It will always supply the current buffer in the `data.saved_buffer`
|
It will always supply the current buffer in the `data.saved_buffer`
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ local function save(buf)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
autocmds.exec_autocmd("AutoSaveWritePre", buf)
|
autocmds.exec_autocmd("AutoSaveWritePre", { saved_buffer = buf })
|
||||||
|
|
||||||
local noautocmd = cnf.opts.noautocmd and "noautocmd " or ""
|
local noautocmd = cnf.opts.noautocmd and "noautocmd " or ""
|
||||||
if cnf.opts.write_all_buffers then
|
if cnf.opts.write_all_buffers then
|
||||||
@@ -90,7 +90,7 @@ local function save(buf)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
autocmds.exec_autocmd("AutoSaveWritePost", buf)
|
autocmds.exec_autocmd("AutoSaveWritePost", { saved_buffer = buf })
|
||||||
logger.log(buf, "Saved buffer")
|
logger.log(buf, "Saved buffer")
|
||||||
|
|
||||||
if cnf.opts.execution_message.enabled == true then
|
if cnf.opts.execution_message.enabled == true then
|
||||||
@@ -163,12 +163,16 @@ function M.on()
|
|||||||
})
|
})
|
||||||
|
|
||||||
autosave_running = true
|
autosave_running = true
|
||||||
|
|
||||||
|
autocmds.exec_autocmd("AutoSaveEnable")
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.off()
|
function M.off()
|
||||||
autocmds.create_augroup({ clear = true })
|
autocmds.create_augroup({ clear = true })
|
||||||
|
|
||||||
autosave_running = false
|
autosave_running = false
|
||||||
|
|
||||||
|
autocmds.exec_autocmd("AutoSaveDisable")
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.toggle()
|
function M.toggle()
|
||||||
|
|||||||
@@ -20,9 +20,13 @@ M.create_augroup = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- @param pattern string
|
--- @param pattern string
|
||||||
--- @param saved_buffer number
|
--- @param data? table
|
||||||
M.exec_autocmd = function(pattern, saved_buffer)
|
M.exec_autocmd = function(pattern, data)
|
||||||
api.nvim_exec_autocmds("User", { pattern = pattern, data = { saved_buffer = saved_buffer } })
|
local opts = { pattern = pattern }
|
||||||
|
if data ~= nil then
|
||||||
|
opts.data = data
|
||||||
|
end
|
||||||
|
api.nvim_exec_autocmds("User", opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param trigger_events TriggerEvent[]?
|
--- @param trigger_events TriggerEvent[]?
|
||||||
|
|||||||
Reference in New Issue
Block a user