summaryrefslogtreecommitdiff
path: root/lua/telescope
diff options
context:
space:
mode:
authorruniq <patrice.peterson@mailbox.org>2021-05-31 08:47:05 +0200
committerGitHub <noreply@github.com>2021-05-31 08:47:05 +0200
commite659e3336f6134bc25e809648835d71aa4ac2b06 (patch)
tree57b8ceb76a811246a54aad0a8a582e54746c01ab /lua/telescope
parent654b11aa08e54255a55625e6bca514b9659b7896 (diff)
feat: send to loclist (#868)
Diffstat (limited to 'lua/telescope')
-rw-r--r--lua/telescope/actions/init.lua59
1 files changed, 52 insertions, 7 deletions
diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua
index b8b1957..f7864a9 100644
--- a/lua/telescope/actions/init.lua
+++ b/lua/telescope/actions/init.lua
@@ -489,7 +489,7 @@ local entry_to_qf = function(entry)
}
end
-local send_selected_to_qf = function(prompt_bufnr, mode)
+local send_selected_to_qf = function(prompt_bufnr, mode, target)
local picker = action_state.get_current_picker(prompt_bufnr)
local qf_entries = {}
@@ -499,10 +499,14 @@ local send_selected_to_qf = function(prompt_bufnr, mode)
actions.close(prompt_bufnr)
- vim.fn.setqflist(qf_entries, mode)
+ if target == 'loclist' then
+ vim.fn.setloclist(picker.original_win_id, qf_entries, mode)
+ else
+ vim.fn.setqflist(qf_entries, mode)
+ end
end
-local send_all_to_qf = function(prompt_bufnr, mode)
+local send_all_to_qf = function(prompt_bufnr, mode, target)
local picker = action_state.get_current_picker(prompt_bufnr)
local manager = picker.manager
@@ -513,7 +517,11 @@ local send_all_to_qf = function(prompt_bufnr, mode)
actions.close(prompt_bufnr)
- vim.fn.setqflist(qf_entries, mode)
+ if target == 'loclist' then
+ vim.fn.setloclist(picker.original_win_id, qf_entries, mode)
+ else
+ vim.fn.setqflist(qf_entries, mode)
+ end
end
--- Sends the selected entries to the quickfix list, replacing the previous entries.
@@ -536,12 +544,32 @@ actions.add_to_qflist = function(prompt_bufnr)
send_all_to_qf(prompt_bufnr, 'a')
end
-local smart_send = function(prompt_bufnr, mode)
+ --- Sends the selected entries to the location list, replacing the previous entries.
+actions.send_selected_to_loclist = function(prompt_bufnr)
+ send_selected_to_qf(prompt_bufnr, 'r', 'loclist')
+end
+
+ --- Adds the selected entries to the location list, keeping the previous entries.
+actions.add_selected_to_loclist = function(prompt_bufnr)
+ send_selected_to_qf(prompt_bufnr, 'a', 'loclist')
+end
+
+ --- Sends all entries to the location list, replacing the previous entries.
+actions.send_to_loclist = function(prompt_bufnr)
+ send_all_to_qf(prompt_bufnr, 'r', 'loclist')
+end
+
+ --- Adds all entries to the location list, keeping the previous entries.
+actions.add_to_loclist = function(prompt_bufnr)
+ send_all_to_qf(prompt_bufnr, 'a', 'loclist')
+end
+
+local smart_send = function(prompt_bufnr, mode, target)
local picker = action_state.get_current_picker(prompt_bufnr)
if table.getn(picker:get_multi_selection()) > 0 then
- send_selected_to_qf(prompt_bufnr, mode)
+ send_selected_to_qf(prompt_bufnr, mode, target)
else
- send_all_to_qf(prompt_bufnr, mode)
+ send_all_to_qf(prompt_bufnr, mode, target)
end
end
@@ -557,6 +585,18 @@ actions.smart_add_to_qflist = function(prompt_bufnr)
smart_send(prompt_bufnr, 'a')
end
+--- Sends the selected entries to the location list, replacing the previous entries.
+--- If no entry was selected, sends all entries.
+actions.smart_send_to_loclist = function(prompt_bufnr)
+ smart_send(prompt_bufnr, 'r', 'loclist')
+end
+
+--- Adds the selected entries to the location list, keeping the previous entries.
+--- If no entry was selected, adds all entries.
+actions.smart_add_to_loclist = function(prompt_bufnr)
+ smart_send(prompt_bufnr, 'a', 'loclist')
+end
+
actions.complete_tag = function(prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)
local tags = current_picker.sorter.tags
@@ -605,6 +645,11 @@ actions.open_qflist = function(_)
vim.cmd [[copen]]
end
+--- Open the location list
+actions.open_loclist = function(_)
+ vim.cmd [[lopen]]
+end
+
-- ==================================================
-- Transforms modules and sets the corect metatables.
-- ==================================================