From 2e3ebd3b8e2fbf88e1681ef52248ad3de1c4a251 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Tue, 8 Feb 2022 23:57:02 +0100 Subject: vim: markdown: add link preview helper --- .vim/lua/job.lua | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to '.vim/lua/job.lua') diff --git a/.vim/lua/job.lua b/.vim/lua/job.lua index 9a235c4..c14e978 100644 --- a/.vim/lua/job.lua +++ b/.vim/lua/job.lua @@ -7,7 +7,7 @@ local M = { } --create a new job and register ---@return /usr/local/share/nvim/site/pack/packer/start/plenary.nvim/lua/plenary/job.lua +--@return ~/.local/share/nvim/site/pack/packer/start/plenary.nvim/lua/plenary/job.lua function M.jobstart(opts) opts = opts or {} @@ -19,14 +19,20 @@ function M.jobstart(opts) title = opts.command end + if opts.populate_quickfix == nil then + opts.populate_quickfix = true + end + opts.enable_recording = true -- enable job:result() - opts.on_exit = vim.schedule_wrap(function(j, _) + opts.on_exit = vim.schedule_wrap(function(j, code) spinner.on_progress('end', j.pid, j.pid) spinner.on_exit(nil, nil, j.pid) - local lines = j:result() - if not lines or #lines < 1 then + local lines + if code == 0 then + lines = j:result() + else lines = j:stderr_result() end @@ -35,12 +41,13 @@ function M.jobstart(opts) lines[i] = (lines[i]):gsub(string.char(27) .. '[[0-9;]*m', '') end - vim.fn.setqflist({}, ' ', { - title = title, - lines = lines, - }) - - if #lines > 0 then + -- only show quickfix if there is output + if opts.populate_quickfix and #lines > 0 then + vim.bo.errorformat = '%m' + vim.fn.setqflist({}, 'r', { + title = title, + items = lines, + }) vim.api.nvim_command('doautocmd QuickFixCmdPost') end -- cgit 1.4.1