-
Notifications
You must be signed in to change notification settings - Fork 152
feature request: Add events to allow integrations #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Here are events provided by nvim-tree, just for the reference:
|
+1 to this! @wojciech-kulik really appreciate all your work to support mac/ios dev in nvim so far. Found this because I prefer using oil and was curious on how to integrate it with your current work, turns out you are already working on it 😄 |
@rchatham haha, nice to meet you here, the internet is a small place 😂 |
Having events would help me too. |
Okay, I've added two User autocmds that you can subscribe to: Lines 11 to 16 in 32e18df
The full definition of the shapes of actions can be found in these type definitions: oil.nvim/lua/oil/mutator/init.lua Lines 18 to 48 in 32e18df
And here's a simple example of subscribing to the events: vim.api.nvim_create_autocmd("User", {
pattern = "OilActionsPre",
callback = function(args) vim.print(args) end,
})
vim.api.nvim_create_autocmd("User", {
pattern = "OilActionsPost",
callback = function(args)
-- If err is non-null, we encountered an error while processing the actions
if args.data.err then
vim.print("ERROR", args.data.err)
else
vim.print(args)
end
end,
}) |
A practical example. Deleting a file with oil will close the buf open with that file (if any) ---@param url string
---@return nil|string
---@return nil|string
local parse_url = function(url)
return url:match "^.*://(.*)$"
end
vim.api.nvim_create_autocmd("User", {
pattern = "OilActionsPost",
callback = function(args)
if args.data.err == nil then
for _, action in ipairs(args.data.actions) do
if action.type == "delete" then
local path = parse_url(action.url)
local bufnr = vim.fn.bufnr(path)
if bufnr == -1 then
return
end
vim.t.bufs = vim.tbl_filter(function(b)
return b ~= bufnr
end, vim.t.bufs)
vim.cmd("bdelete " .. bufnr)
end
end
end
end,
}) Screen.Recording.2024-03-17.at.23.50.58.mov❤️ Thank you for making this possible @stevearc |
Thank you @stevearc! |
@stevearc I get this error when I try moving a file from one folder to another: I figured out that it happens because I use a binding that calls |
@wojciech-kulik please file this as a new issue with complete reproduction steps |
Integration based on: stevearc/oil.nvim#310
I updated @wSedlacek version to: -- close deleted files via oil.nvim
vim.api.nvim_create_autocmd("User", {
pattern = "OilActionsPost",
callback = function(args)
local parse_url = function(url)
return url:match("^.*://(.*)$")
end
if args.data.err then
return
end
for _, action in ipairs(args.data.actions) do
if action.type == "delete" and action.entry_type == "file" then
local path = parse_url(action.url)
local bufnr = vim.fn.bufnr(path)
if bufnr == -1 then
return
end
vim.cmd("bw " .. bufnr)
end
end
end,
}) However, it looks like I can't delete any buffer when floating oil is visible. Even if I manually run Any ideas why it is happening? Ok, I figured it out, I can't wipe out a buffer that is the last one visible. So the fix is to just navigate first to the previous one: vim.cmd("bp | bw " .. bufnr) |
I improved the version above: -- close deleted files via oil.nvim
vim.api.nvim_create_autocmd("User", {
pattern = "OilActionsPost",
callback = function(args)
local parse_url = function(url)
return url:match("^.*://(.*)$")
end
if args.data.err then
return
end
for _, action in ipairs(args.data.actions) do
if action.type == "delete" and action.entry_type == "file" then
local path = parse_url(action.url)
local bufnr = vim.fn.bufnr(path)
if bufnr == -1 then
return
end
local winnr = vim.fn.win_findbuf(bufnr)[1]
if not winnr then
return
end
vim.fn.win_execute(winnr, "bfirst | bw " .. bufnr)
end
end
end,
}) as we are still in Oil, we need to use |
Did you check existing requests?
Describe the feature
It would be great to be able to subscribe to CRUD events (add/delete/rename) for files and folders. It would allow for integration with other plugins.
Provide background
I'm working on a plugin (xcodebuild.nvim) that allows you to manage project files, each change in file structure must update project file. Currently, I provide simple functions to work with files, but for users it would be much more convenient to use their file manager. I'm already working on integration with nvim-tree, because they expose events. However, as far as I was able to check there is no such thing in Oil.
What is the significance of this feature?
strongly desired
Additional details
No response
The text was updated successfully, but these errors were encountered: