1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-13 02:05:40 +08:00

feat(flygrep): add apply_to_quickfix function

This commit is contained in:
wsdjeg 2022-10-10 01:52:19 +08:00
parent b8580415e7
commit 2212c00c5e
2 changed files with 36 additions and 2 deletions

View File

@ -67,7 +67,8 @@ function M._handle_input(...)
while not M._quit do while not M._quit do
local char = M.__vim.getchar() local char = M.__vim.getchar()
if M._function_key[char] ~= nil then if M._function_key[char] ~= nil then
pcall(M._function_key[char]) local ok, rst = pcall(M._function_key[char])
if not ok then print(rst) end
goto continue goto continue
end end
if M._c_r_mode then if M._c_r_mode then

View File

@ -316,7 +316,7 @@ local function open_item(...)
jobstop(grepid) jobstop(grepid)
end end
mpt._clear_prompt() mpt._clear_prompt()
mpt._quit = 1 mpt._quit = true
local filename, liner, colum = get_file_pos(line) local filename, liner, colum = get_file_pos(line)
if previous_able then if previous_able then
close_preview_win() close_preview_win()
@ -369,6 +369,39 @@ local function toggle_expr_mode()
.. mpt._prompt.cursor_end) .. mpt._prompt.cursor_end)
end end
local function apply_to_quickfix()
mpt._handle_fly = flygrep
if vim.fn.getbufline(buffer_id, 1)[1] ~= '' then
if grepid ~= 0 then
jobstop(grepid)
end
mpt._quit = true
if previous_able then
close_preview_win()
end
previous_able = false
local searching_result = vim.api.nvim_buf_get_lines(buffer_id, 0, -1, false)
close_flygrep_win()
update_history()
if vim.fn.empty(searching_result) == 0 then
-- vim.cmd('cgetexpr ' .. vim.fn.join(searching_result, "\n"))
-- vim.cmd([[
-- cgetexpr join(luaeval(searching_result), "\n")
-- ]])
-- vim.fn.setqflist({})
vim.fn.setqflist({}, 'r', {
title = 'FlyGrep partten:' .. mpt._prompt.cursor_begin .. mpt._prompt.cursor_char .. mpt._prompt.cursor_end,
lines = searching_result
})
mpt._clear_prompt()
vim.cmd('copen')
end
vim.cmd('noautocmd normal! :')
end
end
mpt._function_key = { mpt._function_key = {
[Key.t('<Tab>')] = next_item, [Key.t('<Tab>')] = next_item,
[Key.t('<C-j>')] = next_item, [Key.t('<C-j>')] = next_item,