Skip to content

Commit dfb09e8

Browse files
authored
feat: add callback for handling buffer opening (#638)
1 parent 200df01 commit dfb09e8

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lua/oil/init.lua

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ end
618618
---@field split? "aboveleft"|"belowright"|"topleft"|"botright" Split modifier
619619
---@field tab? boolean Open the buffer in a new tab
620620
---@field close? boolean Close the original oil buffer once selection is made
621+
---@field handle_buffer_callback? fun(buf_id: integer) If defined, all other buffer related options here would be ignored. This callback allows you to take over the process of opening the buffer yourself.
621622

622623
---Select the entry under the cursor
623624
---@param opts nil|oil.SelectOpts
@@ -757,15 +758,19 @@ M.select = function(opts, callback)
757758
elseif opts.split then
758759
cmd = "sbuffer"
759760
end
760-
---@diagnostic disable-next-line: param-type-mismatch
761-
local ok, err = pcall(vim.cmd, {
762-
cmd = cmd,
763-
args = { filebufnr },
764-
mods = mods,
765-
})
766-
-- Ignore swapfile errors
767-
if not ok and err and not err:match("^Vim:E325:") then
768-
vim.api.nvim_echo({ { err, "Error" } }, true, {})
761+
if opts.handle_buffer_callback ~= nil then
762+
opts.handle_buffer_callback(filebufnr)
763+
else
764+
---@diagnostic disable-next-line: param-type-mismatch
765+
local ok, err = pcall(vim.cmd, {
766+
cmd = cmd,
767+
args = { filebufnr },
768+
mods = mods,
769+
})
770+
-- Ignore swapfile errors
771+
if not ok and err and not err:match("^Vim:E325:") then
772+
vim.api.nvim_echo({ { err, "Error" } }, true, {})
773+
end
769774
end
770775

771776
open_next_entry(cb)

0 commit comments

Comments
 (0)