chore: close window and buffer more safely

This commit is contained in:
JuanZoran
2023-04-07 19:05:24 +08:00
parent fcde85544a
commit 38b8e20729
7 changed files with 17 additions and 20 deletions

View File

@ -37,7 +37,7 @@ end
---Destory buffer
function buffer:destroy()
api.nvim_buf_delete(self.bufnr, { force = true })
pcall(api.nvim_buf_delete, self.bufnr, { force = true })
end
---Set buffer load keymap

View File

@ -37,7 +37,7 @@ function M.new(opts)
data.backends[i] = Trans.backend[name]
end
if Trans.util.is_English(str) then
if Trans.util.is_english(str) then
data.from = 'en'
data.to = 'zh'
else

View File

@ -59,8 +59,7 @@ local strategy = {
local name = backend.name
---@cast backend TransBackend
while result[name] == nil do
if not update(backend) then break end
while result[name] == nil and update(backend) do
end
if result[name] then return true end
@ -72,7 +71,6 @@ local strategy = {
}
-- HACK : Core process logic
local function process(opts)
opts = init_opts(opts)

View File

@ -72,7 +72,7 @@ end
---Detect whether the string is English
---@param str string
---@return boolean
function M.is_English(str)
function M.is_english(str)
local char = { str:byte(1, -1) }
for i = 1, #str do
if char[i] > 128 then

View File

@ -124,7 +124,8 @@ function window:try_close()
}
end
api.nvim_win_close(self.winid, true)
pcall(api.nvim_win_close, self.winid, true)
end
---Set window local highlight group

View File

@ -39,9 +39,9 @@ local function check_binary_dependencies()
}
binary_dependencies[3] = ({
win = 'node',
mac = 'say',
linux = 'festival',
win = 'node',
mac = 'say',
linux = 'festival',
termux = 'termux-api-speak',
})[Trans.system]