diff options
Diffstat (limited to '.vim')
| -rw-r--r-- | .vim/lua/job.lua | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/.vim/lua/job.lua b/.vim/lua/job.lua index c14e978..657a72d 100644 --- a/.vim/lua/job.lua +++ b/.vim/lua/job.lua @@ -11,6 +11,15 @@ local M = { function M.jobstart(opts) opts = opts or {} + -- required options + vim.tbl_extend('force', opts, { + enable_recording = true, -- enable job:result() + }) + + -- default options + opts.populate_quickfix = opts.populate_quickfix or true + opts.enable_spinner = opts.enable_spinner or true + local title if opts.format_title then title = opts.format_title(opts.command, opts.args) @@ -19,15 +28,12 @@ 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, code) - spinner.on_progress('end', j.pid, j.pid) - spinner.on_exit(nil, nil, j.pid) + if opts.enable_spinner then + spinner.on_progress('end', j.pid, j.pid) + spinner.on_exit(nil, nil, j.pid) + table.remove(M.current_jobs, j.pid) + end local lines if code == 0 then @@ -43,34 +49,30 @@ function M.jobstart(opts) -- 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, + lines = lines, + efm = '%m', }) - vim.api.nvim_command('doautocmd QuickFixCmdPost') - end - - for k, v in ipairs(M.current_jobs) do - if v.pid == j.pid then - table.remove(M.current_jobs, k) - break - end + vim.cmd([[doautocmd QuickFixCmdPost]]) end end) local j = Job:new(opts) j:start() - table.insert(M.current_jobs, j) + M.current_jobs[j.pid] = j - spinner.on_attach(j.pid, title, vim.fn.bufnr()) - spinner.on_progress('begin', j.pid, j.pid) + if opts.enable_spinner then + spinner.on_attach(j.pid, title, vim.fn.bufnr()) + spinner.on_progress('begin', j.pid, j.pid) + end return j end function M.make(extra_args) local makeprg = vim.fn.expandcmd(vim.opt.makeprg:get()) + -- split makeprg into command + args local args = vim.split(makeprg, ' ') local command = args[1] table.remove(args, 1) @@ -89,6 +91,7 @@ function M.sh(command_string) command = vim.env.SHELL, args = {'-c', command_string}, + -- strip 'sh -c' from the title (used by progress reporting etc.) format_title = function(_, args) return List(args):slice(2,#args):join(' ') end |