2023-01-15 00:17:41 +07:00
|
|
|
local M = {}
|
|
|
|
|
|
|
|
function M.smart_quit()
|
2024-05-22 06:39:38 +07:00
|
|
|
local bufnr = vim.api.nvim_get_current_buf()
|
|
|
|
local buf_windows = vim.call("win_findbuf", bufnr)
|
|
|
|
local modified = vim.api.nvim_buf_get_var(bufnr, "modified")
|
|
|
|
if modified and #buf_windows == 1 then
|
|
|
|
vim.ui.input({
|
|
|
|
prompt = "You have unsaved changes. Quit anyway? (y/n) ",
|
|
|
|
}, function(input)
|
|
|
|
if input == "y" then
|
|
|
|
vim.cmd "q!"
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
else
|
|
|
|
vim.cmd "q!"
|
|
|
|
end
|
2023-01-15 00:17:41 +07:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.isempty(s)
|
2024-05-22 06:39:38 +07:00
|
|
|
return s == nil or s == ""
|
2023-01-15 00:17:41 +07:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.get_buf_option(opt)
|
2024-05-22 06:39:38 +07:00
|
|
|
local status_ok, buf_option = pcall(vim.api.nvim_buf_get_var, 0, opt)
|
|
|
|
if not status_ok then
|
|
|
|
return nil
|
|
|
|
else
|
|
|
|
return buf_option
|
|
|
|
end
|
2023-01-15 00:17:41 +07:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|