Update neovim_luma_preview.lua
This commit is contained in:
@@ -40,7 +40,15 @@ local function update_luma_preview()
|
|||||||
local src_buf = vim.api.nvim_get_current_buf()
|
local src_buf = vim.api.nvim_get_current_buf()
|
||||||
local lines = vim.api.nvim_buf_get_lines(src_buf, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(src_buf, 0, -1, false)
|
||||||
local changedtick = vim.api.nvim_buf_get_changedtick(src_buf)
|
local changedtick = vim.api.nvim_buf_get_changedtick(src_buf)
|
||||||
local cmd = vim.env.LUMA_MARKDOWN_BIN or "luma_markdown"
|
local configured_cmd = vim.env.LUMA_MARKDOWN_BIN or "luma_markdown"
|
||||||
|
-- jobstart does not invoke a shell, so expand "~" explicitly. This also
|
||||||
|
-- keeps executable lookup working for a command supplied through PATH.
|
||||||
|
local cmd = vim.fn.expand(configured_cmd)
|
||||||
|
|
||||||
|
if vim.fn.executable(cmd) == 0 then
|
||||||
|
vim.notify("Luma preview executable not found: " .. configured_cmd, vim.log.levels.ERROR)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
update_id = update_id + 1
|
update_id = update_id + 1
|
||||||
local this_update = update_id
|
local this_update = update_id
|
||||||
@@ -53,7 +61,7 @@ local function update_luma_preview()
|
|||||||
local output = {}
|
local output = {}
|
||||||
local errors = {}
|
local errors = {}
|
||||||
local job
|
local job
|
||||||
job = vim.fn.jobstart({ cmd }, {
|
local started, result = pcall(vim.fn.jobstart, { cmd }, {
|
||||||
stdin = "pipe",
|
stdin = "pipe",
|
||||||
stdout_buffered = true,
|
stdout_buffered = true,
|
||||||
stderr_buffered = true,
|
stderr_buffered = true,
|
||||||
@@ -83,11 +91,12 @@ local function update_luma_preview()
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
if job <= 0 then
|
if not started or result <= 0 then
|
||||||
vim.notify("Could not start Luma preview: " .. cmd, vim.log.levels.ERROR)
|
vim.notify("Could not start Luma preview: " .. cmd, vim.log.levels.ERROR)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
job = result
|
||||||
active_job = job
|
active_job = job
|
||||||
vim.fn.chansend(job, table.concat(lines, "\n"))
|
vim.fn.chansend(job, table.concat(lines, "\n"))
|
||||||
vim.fn.chanclose(job, "stdin")
|
vim.fn.chanclose(job, "stdin")
|
||||||
|
|||||||
Reference in New Issue
Block a user