diff --git a/lua/lvim/core/bufferline.lua b/lua/lvim/core/bufferline.lua index 27318a18..fba3e84a 100644 --- a/lua/lvim/core/bufferline.lua +++ b/lua/lvim/core/bufferline.lua @@ -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,19 +187,24 @@ 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")) + 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 - 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 - end) - return + choice = fn.confirm(fmt([[Close "%s"?]], bufname), "&Yes\n&No\n&Cancel") + if choice == 1 then + force = true + else + return + end end end