From 805c03609f83a8e33122fa85033af45a14a3bdab Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 1 Jan 2025 20:34:26 +0800 Subject: [PATCH] feat(quickfix): add quickfix.nvim --- autoload/SpaceVim/layers/core.vim | 8 +++ bundle/quickfix.nvim/README.md | 0 bundle/quickfix.nvim/lua/quickfix.lua | 79 ++++++++++++++++++++++++ bundle/quickfix.nvim/plugin/quickfix.lua | 9 +++ 4 files changed, 96 insertions(+) create mode 100644 bundle/quickfix.nvim/README.md create mode 100644 bundle/quickfix.nvim/lua/quickfix.lua create mode 100644 bundle/quickfix.nvim/plugin/quickfix.lua diff --git a/autoload/SpaceVim/layers/core.vim b/autoload/SpaceVim/layers/core.vim index 3e3d96fc1..98d7be2a2 100644 --- a/autoload/SpaceVim/layers/core.vim +++ b/autoload/SpaceVim/layers/core.vim @@ -152,6 +152,7 @@ endif let s:enable_smooth_scrolling = 1 let s:enable_netrw = 0 +let s:enable_quickfix_key_bindings = 0 let g:_spacevim_enable_filetree_gitstatus = 0 let g:_spacevim_enable_filetree_filetypeicon = 0 @@ -238,6 +239,10 @@ function! SpaceVim#layers#core#plugins() abort \}]) call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-grepper' , { 'on_cmd' : 'Grepper', \ 'loadconf' : 1} ]) + + if s:enable_quickfix_key_bindings + call add(plugins, [g:_spacevim_root_dir . 'bundle/quickfix.nvim' , { 'merged' : 0} ]) + endif return plugins endfunction @@ -1213,6 +1218,9 @@ function! SpaceVim#layers#core#set_variable(var) abort let s:enable_netrw = get(a:var, \ 'enable_netrw', \ 0) + let s:enable_quickfix_key_bindings = get(a:var, + \ 'enable_quickfix_key_bindings', + \ s:enable_quickfix_key_bindings) endfunction function! s:defx_find_current_file() abort diff --git a/bundle/quickfix.nvim/README.md b/bundle/quickfix.nvim/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/bundle/quickfix.nvim/lua/quickfix.lua b/bundle/quickfix.nvim/lua/quickfix.lua new file mode 100644 index 000000000..b5ccecedb --- /dev/null +++ b/bundle/quickfix.nvim/lua/quickfix.lua @@ -0,0 +1,79 @@ +--============================================================================= +-- qf.lua +-- Copyright 2025 Eric Wong +-- Author: Eric Wong < wsdjeg@outlook.com > +-- URL: https://spacevim.org +-- License: GPLv3 +--============================================================================= + +local M = {} + +M.setup = function() + local group = vim.api.nvim_create_augroup('quickfix_mapping', { + clear = true, + }) + + vim.api.nvim_create_autocmd({ 'FileType' }, { + pattern = 'qf', + group = group, + callback = function(ev) + vim.keymap.set('n', 'dd', function() + local qflist = vim.fn.getqflist() + local line = vim.fn.line('.') + table.remove(qflist, line) + vim.fn.setqflist(qflist) + vim.cmd(tostring(line)) + end, { buffer = ev.buf }) + end, + }) + + local function table_remove(t, from, to) + local rst = {} + for i = 1, #t, 1 do + if i < from or i > to then + rst[#rst + 1] = t[i] + end + end + return rst + end + + vim.api.nvim_create_autocmd({ 'FileType' }, { + pattern = 'qf', + group = group, + callback = function(ev) + vim.keymap.set('v', 'd', function() + local esc = vim.api.nvim_replace_termcodes('', true, false, true) + vim.api.nvim_feedkeys(esc, 'x', false) + local qflist = vim.fn.getqflist() + local from = vim.fn.getpos("'<")[2] + local to = vim.fn.getpos("'>")[2] + if from > to then + from, to = to, from + end + qflist = table_remove(qflist, from, to) + vim.fn.setqflist(qflist) + vim.cmd(tostring(from)) + end, { buffer = ev.buf }) + end, + }) + vim.api.nvim_create_autocmd({ 'FileType' }, { + pattern = 'qf', + group = group, + callback = function(ev) + vim.keymap.set('n', 'c', function() + local input_pattern = vim.fn.input('filter pattern:') + -- vim.cmd('noautocmd normal! :') + local re = vim.regex(input_pattern) + local qf = {} + for _, item in ipairs(vim.fn.getqflist()) do + if not re:match_str(vim.fn.bufname(item.bufnr)) then + table.insert(qf, item) + end + end + vim.fn.setqflist(qf) + end, { buffer = ev.buf }) + end, + }) +end + +return M diff --git a/bundle/quickfix.nvim/plugin/quickfix.lua b/bundle/quickfix.nvim/plugin/quickfix.lua new file mode 100644 index 000000000..af670c1a3 --- /dev/null +++ b/bundle/quickfix.nvim/plugin/quickfix.lua @@ -0,0 +1,9 @@ +--============================================================================= +-- quickfix.lua +-- Copyright 2025 Eric Wong +-- Author: Eric Wong < wsdjeg@outlook.com > +-- URL: https://spacevim.org +-- License: GPLv3 +--============================================================================= + +require('quickfix').setup()