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:
Barrett Ruth 2026-03-06 15:19:32 -05:00 committed by GitHub
parent 69d85b8de1
commit 1ee6c6b259
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 176 additions and 108 deletions

View file

@ -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 } }