feat: add cleanup_buffers_on_delete option (#73)
Problem: When files are deleted via canola, any open Neovim buffers for those files remain alive, polluting the jumplist with stale entries. Solution: Add an opt-in `cleanup_buffers_on_delete` config option (default `false`). When enabled, `finish()` in `mutator/init.lua` iterates completed delete actions and wipes matching buffers via `nvim_buf_delete` before `CanolaActionsPost` fires. Only local filesystem deletes are handled (guarded by the `files` adapter check).
This commit is contained in:
parent
69d85b8de1
commit
1ee6c6b259
5 changed files with 176 additions and 108 deletions
|
|
@ -420,6 +420,21 @@ M.process_actions = function(actions, cb)
|
|||
finished = true
|
||||
progress:close()
|
||||
progress = nil
|
||||
if config.cleanup_buffers_on_delete and not err then
|
||||
for _, action in ipairs(actions) do
|
||||
if action.type == 'delete' then
|
||||
local scheme, path = util.parse_url(action.url)
|
||||
if config.adapters[scheme] == 'files' then
|
||||
assert(path)
|
||||
local os_path = fs.posix_to_os_path(path)
|
||||
local bufnr = vim.fn.bufnr(os_path)
|
||||
if bufnr ~= -1 then
|
||||
vim.api.nvim_buf_delete(bufnr, { force = true })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
vim.api.nvim_exec_autocmds(
|
||||
'User',
|
||||
{ pattern = 'CanolaActionsPost', modeline = false, data = { err = err, actions = actions } }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue