Skip to content

Commit

Permalink
Make close delay configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
vE5li committed Oct 1, 2023
1 parent 956d7fc commit 5fc6c8d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ require("oil").setup({
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,
-- The time in milliseconds it takes for oil buffers to close when no oil buffers are visible
-- Any number <= 0 or any non-number will make the buffers close instantly
close_delay = 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
3 changes: 3 additions & 0 deletions doc/oil.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ OPTIONS *oil-option
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,
-- The time in milliseconds it takes for oil buffers to close when no oil buffers are visible
-- Any number <= 0 or any non-number will make the buffers close instantly
close_delay = 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
3 changes: 3 additions & 0 deletions lua/oil/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ 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,
-- The time in milliseconds it takes for oil buffers to close when no oil buffers are visible
-- Any number <= 0 or any non-number will make the buffers close instantly
close_delay = 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
11 changes: 8 additions & 3 deletions lua/oil/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,16 @@ 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()
-- Check if there is a delay configured for deleting the buffers
if type(config.close_delay) == "number" and config.close_delay > 0 then
vim.defer_fn(function()
M.delete_hidden_buffers()
end, config.close_delay)
else
M.delete_hidden_buffers()
end, 2000)
end
end
end, 10)
end,
Expand Down

0 comments on commit 5fc6c8d

Please sign in to comment.