qftf.lua (1406B)
1 function _G.qftf(info) 2 local items 3 local ret = {} 4 if info.quickfix == 1 then 5 items = vim.fn.getqflist({ id = info.id, items = 0 }).items 6 else 7 items = vim.fn.getloclist(info.winid, { id = info.id, items = 0 }).items 8 end 9 local limit = 31 10 local fname_fmt1, fname_fmt2 = '%-' .. limit .. 's', 'ā¦%.' .. (limit - 1) .. 's' 11 local valid_fmt = '%s ā%4d:%-3dā%s %s' 12 for i = info.start_idx, info.end_idx do 13 local e = items[i] 14 local fname = '' 15 local str 16 if e.valid == 1 then 17 if e.bufnr > 0 then 18 fname = vim.fn.bufname(e.bufnr) 19 if fname == '' then 20 fname = '[No Name]' 21 else 22 fname = fname:gsub('^' .. vim.env.HOME, '~') 23 end 24 -- char in fname may occur more than 1 width, ignore this issue in order to keep performance 25 if #fname <= limit then 26 fname = fname_fmt1:format(fname) 27 else 28 fname = fname_fmt2:format(fname:sub(1 - limit)) 29 end 30 end 31 local lnum = e.lnum > 99999 and -1 or e.lnum 32 local col = e.col > 999 and -1 or e.col 33 local qtype = e.type == '' and '' or ' ' .. e.type:sub(1, 1):upper() 34 local text = e.text:gsub('^%s*(.-)%s*$', '%1') 35 str = valid_fmt:format(fname, lnum, col, qtype, text) 36 else 37 str = e.text 38 end 39 table.insert(ret, str) 40 end 41 return ret 42 end 43 44 -- vim.opt.qftf = '{info -> v:lua._G.qftf(info)}'