aboutsummaryrefslogtreecommitdiffstats
path: root/lua/pi/select_to_quickfix.lua
diff options
context:
space:
mode:
authorElvis Claros Castro <elvis@claros.ar>2024-07-12 11:18:14 -0300
committerElvis Claros Castro <elvis@claros.ar>2024-07-12 11:18:14 -0300
commitea0f4bf8ffade657b1d45152dbc183d4679e75c4 (patch)
treecc1fb023bc308e019ddce33a4b0aed39f56805dc /lua/pi/select_to_quickfix.lua
parent1fd0af14d592d612c2aaab7717c04c8806ba3daa (diff)
downloadnvim-conf-ea0f4bf8ffade657b1d45152dbc183d4679e75c4.tar.gz
nvim-conf-ea0f4bf8ffade657b1d45152dbc183d4679e75c4.zip
Feat: PI
Diffstat (limited to 'lua/pi/select_to_quickfix.lua')
-rw-r--r--lua/pi/select_to_quickfix.lua53
1 files changed, 53 insertions, 0 deletions
diff --git a/lua/pi/select_to_quickfix.lua b/lua/pi/select_to_quickfix.lua
new file mode 100644
index 0000000..ebd1561
--- /dev/null
+++ b/lua/pi/select_to_quickfix.lua
@@ -0,0 +1,53 @@
+local api = vim.api
+
+local function create_quickfix_entry(selection)
+ local filename, linenumber = selection:match "([^:]+):(%d+)"
+
+ return {
+ filename = vim.fn.getcwd() .. "/" .. filename,
+ lnum = tonumber(linenumber),
+ col = 1,
+ text = filename,
+ }
+end
+
+local function add_selections_to_quickfix(selections)
+ local quickfix_list = {}
+
+ for _, selection in ipairs(selections) do
+ local entry = create_quickfix_entry(selection)
+ table.insert(quickfix_list, entry)
+ end
+
+ vim.fn.setqflist(quickfix_list, "r")
+end
+
+local function get_selections()
+ local _, end_line, _, _ = unpack(vim.fn.getpos "'>")
+ local _, start_line, _, _ = unpack(vim.fn.getpos "'<")
+ local lines = api.nvim_buf_get_lines(0, start_line - 1, end_line, false)
+
+ local selections = {}
+ for _, line in ipairs(lines) do
+ for selection in line:gmatch "%S+" do
+ table.insert(selections, selection)
+ end
+ end
+
+ return selections
+end
+
+local function select_to_quickfix()
+ local selections = get_selections()
+
+ if #selections > 0 then
+ add_selections_to_quickfix(selections)
+ print "Selections added to quickfix list"
+ else
+ print "No selections found"
+ end
+end
+
+return {
+ handle = select_to_quickfix,
+}