Skip to content

Commit

Permalink
feat: make buffer cleanup delay configurable (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
vE5li authored Oct 3, 2023
1 parent deba4db commit a9f7f69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lua/oil/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ local default_config = {
trash_command = "trash-put",
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
prompt_save_on_select_new_entry = true,
-- Oil will automatically delete hidden buffers after this delay
-- You can set the delay to false to disable cleanup entirely
-- Note that the cleanup process only starts when none of the oil buffers are currently displayed
cleanup_delay_ms = 2000,
-- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap
-- options with a `callback` (e.g. { callback = function() ... end, desc = "", mode = "n" })
-- Additionally, if it is a string that matches "actions.<name>",
Expand Down
15 changes: 11 additions & 4 deletions lua/oil/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a9f7f69

Please sign in to comment.