-
-
Notifications
You must be signed in to change notification settings - Fork 611
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 API node.buffer.delete, node.buffer.wipe #3040
Changes from 6 commits
71451ea
c72de8c
6de8526
33ff62a
e645b5f
404aae7
2719542
6e598f3
c87c193
343b8a0
199c0c0
ede43ed
0703c47
aa6fe10
2bcb5fe
7a1712e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- Copyright 2019 Yazdani Kiyan under MIT License | ||
local utils = require("nvim-tree.actions.node.utils") | ||
|
||
local M = {} | ||
|
||
---@param filename string | ||
---@param opts ApiNodeDeleteWipeBufferOpts|nil | ||
---@return nil | ||
function M.fn(filename, opts) | ||
utils.delete_buffer("delete", filename, opts) | ||
end | ||
|
||
function M.setup(_) | ||
end | ||
|
||
return M |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tested permutations and combination with 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 commentThe reason will be displayed to describe this comment to others. Learn more. Great! Thank you 👍🏼 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this file can go - everything is in buffer.lua There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah, we can remove this, I forgot to do so, sorry! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
-- Copyright 2019 Yazdani Kiyan under MIT License | ||
local notify = require("nvim-tree.notify") | ||
|
||
local M = {} | ||
|
||
---@alias ApiNodeDeleteWipeBufferMode '"delete"'|'"wipe"' | ||
|
||
---@param mode ApiNodeDeleteWipeBufferMode | ||
---@param filename string | ||
---@param opts ApiNodeDeleteWipeBufferOpts|nil | ||
---@return nil | ||
function M.delete_buffer(mode, filename, opts) | ||
if type(mode) ~= "string" then | ||
mode = "delete" | ||
end | ||
|
||
local buf_fn = vim.cmd.bdelete | ||
if mode == "wipe" then | ||
buf_fn = vim.cmd.bwipe | ||
end | ||
|
||
opts = opts or { force = false } | ||
|
||
local notify_node = notify.render_path(filename) | ||
|
||
-- 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 commentThe 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think just this one. Deleting a modified buffer truly is an error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, done! |
||
return | ||
end | ||
|
||
local force = opts.force | ||
-- check if buffer is modified | ||
local buf_modified = vim.fn.getbufinfo(bufnr_at_filename)[1].changed | ||
if not force and buf_modified == 1 then | ||
notify.error("Buffer for file " .. notify_node .. " is modified") | ||
return | ||
end | ||
|
||
buf_fn({ filename, bang = force }) | ||
end | ||
|
||
return M |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- Copyright 2019 Yazdani Kiyan under MIT License | ||
local utils = require("nvim-tree.actions.node.utils") | ||
|
||
local M = {} | ||
|
||
---@param filename string | ||
---@param opts ApiNodeDeleteWipeBufferOpts|nil | ||
---@return nil | ||
function M.fn(filename, opts) | ||
utils.delete_buffer("wipe", filename, opts) | ||
end | ||
|
||
function M.setup(_) | ||
end | ||
|
||
return M |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ local Api = { | |
}, | ||
run = {}, | ||
open = {}, | ||
buffer = {}, | ||
}, | ||
events = {}, | ||
marks = { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No idea 😅 , this was probably done accidentally. Just reverted it 👍🏼 |
||
---@field path string|nil | ||
---@field current_window boolean|nil default false | ||
---@field winid number|nil | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. |
||
|
||
Api.node.buffer.delete = wrap_node(function(node, opts) | ||
actions.node.delete_buffer.fn(node.absolute_path, opts) | ||
end) | ||
Api.node.buffer.wipe = wrap_node(function(node, opts) | ||
actions.node.wipe_buffer.fn(node.absolute_path, opts) | ||
end) | ||
|
||
Api.git.reload = wrap_explorer("reload_git") | ||
|
||
Api.events.subscribe = events.subscribe | ||
|
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 👍🏼