diff --git a/examples/neovim_luma_preview.lua b/examples/neovim_luma_preview.lua index 5ed29d9..d26a796 100644 --- a/examples/neovim_luma_preview.lua +++ b/examples/neovim_luma_preview.lua @@ -40,7 +40,15 @@ local function update_luma_preview() local src_buf = vim.api.nvim_get_current_buf() local lines = vim.api.nvim_buf_get_lines(src_buf, 0, -1, false) 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 local this_update = update_id @@ -53,7 +61,7 @@ local function update_luma_preview() local output = {} local errors = {} local job - job = vim.fn.jobstart({ cmd }, { + local started, result = pcall(vim.fn.jobstart, { cmd }, { stdin = "pipe", stdout_buffered = true, stderr_buffered = true, @@ -83,11 +91,12 @@ local function update_luma_preview() end, }) - if job <= 0 then + if not started or result <= 0 then vim.notify("Could not start Luma preview: " .. cmd, vim.log.levels.ERROR) return end + job = result active_job = job vim.fn.chansend(job, table.concat(lines, "\n")) vim.fn.chanclose(job, "stdin")