trun_to_neovim_quickfix.lua (1906B)
1 -- Add this to your nvim folder to `plugin/trun.lua`. 2 -- 3 -- use `:Trunqf <name>` to fill quickfix list with lines after last 4 -- success status. It has autocompletion for running truns, press <tab> to list 5 -- those. 6 -- 7 -- !important 8 -- Handler needs to store the output inside file and path to that file must be 9 -- added as second line to status file. viz->examples/handler_tmp_output_file.lua 10 -- 11 -- returns list of running truns 12 local complete = function() 13 local status_dir_def = os.getenv('XDG_CACHE_HOME') .. '/trun' 14 local status_dir = os.getenv('TRUN_STATUS_DIR') or status_dir_def 15 local ls = io.popen('ls ' .. status_dir) 16 local truns = {} 17 for trun in ls:lines() do 18 local name = trun:match('(.*)%..*') 19 table.insert(truns, name) 20 end 21 return truns 22 end 23 24 -- add trun to quickfix list 25 -- it needs to have its tempfile for output 26 local to_qf = function(name) 27 if not name then 28 return 29 end 30 vim.fn.setqflist({}, 'r') 31 -- Depends on `trun-status` viz->tools/trun-status.lua 32 local handle = io.popen('trun-status ' .. name) 33 local o = {} 34 for line in handle:lines() do 35 table.insert(o, line) 36 end 37 if #o == 0 then 38 print('No running trun for "' .. name .. '"') 39 return 40 end 41 -- edit this if path to tmpfile(errorfile) is on another line 42 local errorfile = o[2] 43 if errorfile then 44 local errfile = io.open(errorfile, 'r') 45 local lines = {} 46 for line in errfile:lines() do 47 table.insert(lines, line) 48 end 49 vim.fn.setqflist({}, ' ', {lines = lines}) 50 vim.cmd [[ copen ]] 51 vim.cmd [[ normal G ]] 52 else 53 print('Trun for "' .. name .. '" does not have tmp file') 54 return 55 end 56 end 57 58 -- Make functions globally accessible 59 _G.Trun = {complete = complete, qf = to_qf} 60 61 vim.cmd [[ 62 fun! TrunComplete(A,L,P) 63 return v:lua.Trun.complete() 64 endfun 65 ]] 66 vim.cmd [[command! -nargs=1 -complete=customlist,TrunComplete Trunqf lua Trun.qf("<args>")]]