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
|
||||
- `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`
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ local function save(buf)
|
||||
return
|
||||
end
|
||||
|
||||
autocmds.exec_autocmd("AutoSaveWritePre", buf)
|
||||
autocmds.exec_autocmd("AutoSaveWritePre", { saved_buffer = buf })
|
||||
|
||||
local noautocmd = cnf.opts.noautocmd and "noautocmd " or ""
|
||||
if cnf.opts.write_all_buffers then
|
||||
@@ -90,7 +90,7 @@ local function save(buf)
|
||||
end)
|
||||
end
|
||||
|
||||
autocmds.exec_autocmd("AutoSaveWritePost", buf)
|
||||
autocmds.exec_autocmd("AutoSaveWritePost", { saved_buffer = buf })
|
||||
logger.log(buf, "Saved buffer")
|
||||
|
||||
if cnf.opts.execution_message.enabled == true then
|
||||
@@ -163,12 +163,16 @@ function M.on()
|
||||
})
|
||||
|
||||
autosave_running = true
|
||||
|
||||
autocmds.exec_autocmd("AutoSaveEnable")
|
||||
end
|
||||
|
||||
function M.off()
|
||||
autocmds.create_augroup({ clear = true })
|
||||
|
||||
autosave_running = false
|
||||
|
||||
autocmds.exec_autocmd("AutoSaveDisable")
|
||||
end
|
||||
|
||||
function M.toggle()
|
||||
|
||||
@@ -20,9 +20,13 @@ M.create_augroup = function(opts)
|
||||
end
|
||||
|
||||
--- @param pattern string
|
||||
--- @param saved_buffer number
|
||||
M.exec_autocmd = function(pattern, saved_buffer)
|
||||
api.nvim_exec_autocmds("User", { pattern = pattern, data = { saved_buffer = saved_buffer } })
|
||||
--- @param data? table
|
||||
M.exec_autocmd = function(pattern, data)
|
||||
local opts = { pattern = pattern }
|
||||
if data ~= nil then
|
||||
opts.data = data
|
||||
end
|
||||
api.nvim_exec_autocmds("User", opts)
|
||||
end
|
||||
|
||||
--- @param trigger_events TriggerEvent[]?
|
||||
|
||||
Reference in New Issue
Block a user