feat: make buffer cleanup delay configurable (#191)

This commit is contained in:
vE5li 2023-10-03 18:08:28 +02:00 committed by GitHub
parent deba4db1ac
commit a9f7f6927d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View file

@ -258,11 +258,18 @@ M.initialize = function(bufnr)
-- First wait a short time (10ms) for the buffer change to settle
vim.defer_fn(function()
local visible_buffers = get_visible_hidden_buffers()
-- Only kick off the 2-second timer if we don't have any visible oil buffers
-- Only delete oil buffers if none of them are visible
if visible_buffers and vim.tbl_isempty(visible_buffers) then
vim.defer_fn(function()
M.delete_hidden_buffers()
end, 2000)
-- Check if cleanup is enabled
if type(config.cleanup_delay_ms) == "number" then
if config.cleanup_delay_ms > 0 then
vim.defer_fn(function()
M.delete_hidden_buffers()
end, config.cleanup_delay_ms)
else
M.delete_hidden_buffers()
end
end
end
end, 10)
end,