1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 10:40:03 +08:00

feat(todo): add ctrl-q to apply results to quickfix

This commit is contained in:
wsdjeg 2023-06-25 14:13:17 +08:00
parent 3be76bca65
commit 5febb52913
2 changed files with 25 additions and 2 deletions

View File

@ -930,7 +930,7 @@ endfunction
function! s:save_current_file() abort
let v:errmsg = ''
silent! update
silent! write
if v:errmsg !=# ''
echohl ErrorMsg
echo v:errmsg

View File

@ -91,6 +91,27 @@ local function open_todo() -- {{{
vim.cmd('noautocmd normal! :')
end
-- }}}
--
local function apply_to_quickfix() -- {{{
local qf = {}
for _, v in ipairs(todos) do
table.insert(qf, {
filename = v.file,
lnum = v.line,
col = v.column,
text = v.title,
type = v.label,
})
end
vim.fn.setqflist({}, 'r', {
title = 'Todos',
items = qf,
})
vim.cmd('close')
vim.cmd(winnr .. 'wincmd w')
vim.cmd('botright copen')
end
-- }}}
local function indexof(t, v) -- {{{
for i, x in ipairs(t) do
@ -158,7 +179,6 @@ local function on_exit(id, data, event) -- {{{
end
-- }}}
-- labels to command line regex
local function get_labels_regex() -- {{{
local sep = ''
@ -255,6 +275,9 @@ local function open_win() -- {{{
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Enter>', '', {
callback = open_todo,
})
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-q>', '', {
callback = apply_to_quickfix,
})
end
-- }}}