nvim: Simplify molten statusline function
Instead of doing all kinds of security checks beforehand, we simply wrap the molten kernel check into a lua protected call and return an empty result if we would error. We only return the symbol if we don't error and we have an active kernel.
This commit is contained in:
parent
38bdf74954
commit
be842ce622
1 changed files with 19 additions and 17 deletions
|
@ -8,26 +8,28 @@ return {
|
|||
-- if molten exists, is initialized and connected to a kernel
|
||||
-- show it in the statusline
|
||||
local function molten()
|
||||
local function checked_pynvim(_, exitcode)
|
||||
-- we don't have access to python, disregard element
|
||||
if has_pynvim == 0 then
|
||||
return ""
|
||||
elseif has_pynvim == 1 then
|
||||
local status_ok, res = pcall(function()
|
||||
return require("molten.status").kernels() ~= ""
|
||||
end)
|
||||
if status_ok and res then
|
||||
return ""
|
||||
end
|
||||
return ""
|
||||
-- we don't know if we have python yet, start a check
|
||||
else
|
||||
vim.system({ "poetry", "env", "info", "-p" }, { text = true }, function(_, exitcode)
|
||||
if exitcode == 0 then
|
||||
has_pynvim = 1
|
||||
else
|
||||
has_pynvim = 0
|
||||
end
|
||||
end)
|
||||
has_pynvim = 0
|
||||
end
|
||||
if has_pynvim == 0 then
|
||||
return ""
|
||||
elseif has_pynvim == -1 then
|
||||
vim.fn.jobstart({ "python", "-c", "from neovim import VERSION" }, { on_exit = checked_pynvim })
|
||||
end
|
||||
if
|
||||
has_pynvim == 1
|
||||
and require("core.util").is_available("molten.status")
|
||||
and require("molten.status").kernels() ~= ""
|
||||
then
|
||||
return ""
|
||||
end
|
||||
return ""
|
||||
end
|
||||
|
||||
-- count number of selected lines and characters
|
||||
|
|
Loading…
Reference in a new issue