From 3079e935c793a9aa1831fd165e28636eb7a87dae Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Thu, 29 Jul 2021 23:39:08 +0200 Subject: vim: cleanup config --- .vim/lua/job.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .vim/lua/job.lua (limited to '.vim/lua/job.lua') diff --git a/.vim/lua/job.lua b/.vim/lua/job.lua new file mode 100644 index 0000000..a3591e5 --- /dev/null +++ b/.vim/lua/job.lua @@ -0,0 +1,45 @@ + +local M = {} + +function M.jobstart(cmd) + local output = {} + + local function on_event(job_id, data, event) + if event == 'stdout' or event == 'stderr' then + if data then + vim.list_extend(output, data) + end + end + if event == 'exit' then + vim.fn.setqflist({}, ' ', { + title = cmd, + lines = output, + }) + vim.api.nvim_command('doautocmd QuickFixCmdPost') + end + end + + local job_id = require('spinner.job').jobstart(cmd, { + on_stdout = on_event, + on_stderr = on_event, + on_exit = on_event, + stdout_buffered = true, + stderr_buffered = true, + }) + return job_id +end + +function M.make(args) + local args = args or {} + local makeprg = vim.opt.makeprg:get() + local cmd = vim.split(vim.fn.expandcmd(makeprg), ' ') + table.foreach(args, function(_, v) table.insert(cmd, v) end) + return M.jobstart(cmd) +end + +function M.sh(cmd) + local cmd = {vim.env.SHELL, '-c', cmd} + return M.jobstart(cmd) +end + +return M -- cgit 1.4.1