mirror of
https://github.com/LunarVim/LunarVim.git
synced 2024-09-20 10:35:08 +02:00
feat!: use prompts similar to :confirm
in buf_kill
(#4186)
This commit is contained in:
parent
3dce3d86d4
commit
e548d6bc99
1 changed files with 17 additions and 12 deletions
|
@ -178,7 +178,7 @@ function M.buf_kill(kill_command, bufnr, force)
|
|||
local bo = vim.bo
|
||||
local api = vim.api
|
||||
local fmt = string.format
|
||||
local fnamemodify = vim.fn.fnamemodify
|
||||
local fn = vim.fn
|
||||
|
||||
if bufnr == 0 or bufnr == nil then
|
||||
bufnr = api.nvim_get_current_buf()
|
||||
|
@ -187,21 +187,26 @@ function M.buf_kill(kill_command, bufnr, force)
|
|||
local bufname = api.nvim_buf_get_name(bufnr)
|
||||
|
||||
if not force then
|
||||
local warning
|
||||
local choice
|
||||
if bo[bufnr].modified then
|
||||
warning = fmt([[No write since last change for (%s)]], fnamemodify(bufname, ":t"))
|
||||
elseif api.nvim_buf_get_option(bufnr, "buftype") == "terminal" then
|
||||
warning = fmt([[Terminal %s will be killed]], bufname)
|
||||
end
|
||||
if warning then
|
||||
vim.ui.input({
|
||||
prompt = string.format([[%s. Close it anyway? [y]es or [n]o (default: no): ]], warning),
|
||||
}, function(choice)
|
||||
if choice ~= nil and choice:match "ye?s?" then M.buf_kill(kill_command, bufnr, true) end
|
||||
choice = fn.confirm(fmt([[Save changes to "%s"?]], bufname), "&Yes\n&No\n&Cancel")
|
||||
if choice == 1 then
|
||||
vim.api.nvim_buf_call(bufnr, function()
|
||||
vim.cmd("w")
|
||||
end)
|
||||
elseif choice == 2 then
|
||||
force = true
|
||||
else return
|
||||
end
|
||||
elseif api.nvim_buf_get_option(bufnr, "buftype") == "terminal" then
|
||||
choice = fn.confirm(fmt([[Close "%s"?]], bufname), "&Yes\n&No\n&Cancel")
|
||||
if choice == 1 then
|
||||
force = true
|
||||
else
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Get list of windows IDs with the buffer to close
|
||||
local windows = vim.tbl_filter(function(win)
|
||||
|
|
Loading…
Reference in a new issue