-
-
Notifications
You must be signed in to change notification settings - Fork 610
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
feat(#3037): add node API methods for deleting/wiping buffers #3040
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works nicely, I look forward to using it.
- Revert
ApiTreeToggleOpts
change - Change warning level of no-loaded-buffer
- Remove unused options
delete_buffer
andwipe_buffer
- Refactor action methods, message to follow
- Add help at 6.3 API NODE nvim-tree-api.node
lua/nvim-tree/api.lua
Outdated
@@ -131,7 +132,7 @@ end | |||
Api.tree.open = wrap(actions.tree.open.fn) | |||
Api.tree.focus = Api.tree.open | |||
|
|||
---@class ApiTreeToggleOpts | |||
---@class ApiTreeToggleOptsApiTreeTo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for this change? lua/nvim-tree/actions/tree/toggle.lua
is still using this class...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea 😅 , this was probably done accidentally. Just reverted it 👍🏼
@@ -286,6 +287,16 @@ Api.node.navigate.diagnostics.prev_recursive = wrap_node(actions.moves.item.fn({ | |||
Api.node.navigate.opened.next = wrap_node(actions.moves.item.fn({ where = "next", what = "opened" })) | |||
Api.node.navigate.opened.prev = wrap_node(actions.moves.item.fn({ where = "prev", what = "opened" })) | |||
|
|||
---@class ApiNodeDeleteWipeBufferOpts | |||
---@field force boolean|nil default false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
@@ -470,6 +470,8 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS | |||
remove_file = { | |||
close_window = true, | |||
}, | |||
delete_buffer = {}, | |||
wipe_buffer = {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these options used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I was unsure if it was a convention to have these even if there are no underlying options, so I added these in even though they are empty.
I can remove them 👍🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested permutations and combination with :ls!
reporting as expected.
vim.keymap.set("n", "BW", function()
api.node.buffer.wipe(api.tree.get_node_under_cursor(), { force = false })
end, opts("Wipe"))
vim.keymap.set("n", "BD", function()
api.node.buffer.wipe(api.tree.get_node_under_cursor(), { force = true })
end, opts("Delete"))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thank you 👍🏼
-- check if buffer for file at cursor exists and if it is loaded | ||
local bufnr_at_filename = vim.fn.bufnr(filename) | ||
if bufnr_at_filename == -1 or vim.fn.getbufinfo(bufnr_at_filename)[1].loaded == 0 then | ||
notify.error("No loaded buffer coincides with " .. notify_node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please change this to INFO? Users may wish to ignore this message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sure! Should I also change the error statement at line 37 (the one that says "Buffer for file " .. notify_node .. " is modified"
), or just this one?
I like the modularity, it's really easy to read. Having 3 new files is not necessary, delete and wipe can be handled in one place: These actions do act on a node, and belong in
|
Ok, when I get some free time I'll work on these changes. Thanks for the review :) |
This PR adds two API methods for respectively deleting and wiping the buffer for the current file under the tree cursor:
Api.node.buffer.delete
; andApi.node.buffer.wipe
,as discussed in #3037.
They both use the same underlying function defined in the new file added at
lua/actions/node/utils.lua
.This function checks if there's an opened and loaded buffer for the file under the tree cursor.
If there isn't, it notifies an error message.
Otherwise, it deletes/wipes the buffer if it's not modified (unless
opts.force
istrue
)I'm setting this as WIP because I haven't run the make commands yet.EDIT: done