fix error while closing file (#1002)

This commit is contained in:
siduck 2022-05-01 08:01:47 +05:30
parent 985217b93f
commit 9ae7c2aff3
2 changed files with 23 additions and 6 deletions

View File

@ -5,6 +5,7 @@ local g = vim.g
g.did_load_filetypes = 0 g.did_load_filetypes = 0
g.do_filetype_lua = 1 g.do_filetype_lua = 1
opt.confirm = true
opt.laststatus = 3 -- global statusline opt.laststatus = 3 -- global statusline
opt.title = true opt.title = true
opt.clipboard = "unnamedplus" opt.clipboard = "unnamedplus"

View File

@ -3,8 +3,22 @@ local M = {}
local cmd = vim.cmd local cmd = vim.cmd
M.close_buffer = function(force) M.close_buffer = function(force)
if vim.bo.buftype == "terminal" then vim.api.nvim_win_hide(0) return end if vim.bo.buftype == "terminal" then
vim.api.nvim_win_hide(0)
return
end
local fileExists = vim.fn.filereadable(vim.fn.expand "%p")
local modified = vim.api.nvim_buf_get_option(vim.fn.bufnr(), "modified")
-- if file doesnt exist & its modified
if fileExists == 0 and modified then
print "no file name? add it now!"
return
end
force = force or not vim.bo.buflisted or vim.bo.buftype == "nofile" force = force or not vim.bo.buflisted or vim.bo.buftype == "nofile"
-- if not force, change to prev buf and then close current -- if not force, change to prev buf and then close current
local close_cmd = force and ":bd!" or ":bp | bd" .. vim.fn.bufnr() local close_cmd = force and ":bd!" or ":bp | bd" .. vim.fn.bufnr()
vim.cmd(close_cmd) vim.cmd(close_cmd)
@ -96,7 +110,9 @@ end
M.remove_default_plugins = function(plugins) M.remove_default_plugins = function(plugins)
local removals = require("core.utils").load_config().plugins.remove or {} local removals = require("core.utils").load_config().plugins.remove or {}
if not vim.tbl_isempty(removals) then if not vim.tbl_isempty(removals) then
for _, plugin in pairs(removals) do plugins[plugin] = nil end for _, plugin in pairs(removals) do
plugins[plugin] = nil
end
end end
return plugins return plugins
end end