diff --git a/doc/oil.txt b/doc/oil.txt index 0c53129..2660182 100644 --- a/doc/oil.txt +++ b/doc/oil.txt @@ -777,6 +777,45 @@ OilTrash *hl-OilTras OilTrashSourcePath *hl-OilTrashSourcePath* Virtual text that shows the original path of file in the trash +-------------------------------------------------------------------------------- +EVENTS *oil-events* + +Oil emits the following User autocmd events: + +OilEnter *OilEnter* + Fired once when an oil buffer finishes its initial render and is ready for + interaction. The autocmd `data` table contains `{ buf = }`. + + Example: >lua + vim.api.nvim_create_autocmd("User", { + pattern = "OilEnter", + callback = function(args) + -- args.data.buf is the oil buffer number + end, + }) +< + +OilReadPost *OilReadPost* + Fired after every successful render of an oil buffer, including re-renders + triggered by filesystem changes or manual refresh. This fires in addition + to OilEnter on the initial render. + + Useful for third-party plugins that need to update decorations (e.g., git + status columns) whenever the buffer contents change. + + Example: >lua + vim.api.nvim_create_autocmd("User", { + pattern = "OilReadPost", + callback = function(args) + -- args.data.buf is the oil buffer number + end, + }) +< + +OilMutationComplete *OilMutationComplete* + Fired after a mutation (file create, delete, rename, move, copy) finishes + executing. + -------------------------------------------------------------------------------- TRASH *oil-trash* diff --git a/lua/oil/view.lua b/lua/oil/view.lua index b3a216e..bb0408e 100644 --- a/lua/oil/view.lua +++ b/lua/oil/view.lua @@ -867,7 +867,19 @@ local pending_renders = {} ---@param opts nil|table --- refetch nil|boolean Defaults to true ---@param callback nil|fun(err: nil|string) -M.render_buffer_async = function(bufnr, opts, callback) +M.render_buffer_async = function(bufnr, opts, caller_callback) + local function callback(err) + if not err then + vim.api.nvim_exec_autocmds( + "User", + { pattern = "OilReadPost", modeline = false, data = { buf = bufnr } } + ) + end + if caller_callback then + caller_callback(err) + end + end + opts = vim.tbl_deep_extend("keep", opts or {}, { refetch = true, })