From e659e3336f6134bc25e809648835d71aa4ac2b06 Mon Sep 17 00:00:00 2001 From: runiq Date: Mon, 31 May 2021 08:47:05 +0200 Subject: [PATCH] feat: send to loclist (#868) --- doc/telescope.txt | 39 ++++++++++++++++++++++ lua/telescope/actions/init.lua | 59 ++++++++++++++++++++++++++++++---- 2 files changed, 91 insertions(+), 7 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index ee0aa6a..73348d3 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -313,6 +313,28 @@ actions.add_to_qflist() *actions.add_to_qflist()* +actions.send_selected_to_loclist() *actions.send_selected_to_loclist()* + Sends the selected entries to the location list, replacing the previous + entries. + + + +actions.add_selected_to_loclist() *actions.add_selected_to_loclist()* + Adds the selected entries to the location list, keeping the previous + entries. + + + +actions.send_to_loclist() *actions.send_to_loclist()* + Sends all entries to the location list, replacing the previous entries. + + + +actions.add_to_loclist() *actions.add_to_loclist()* + Adds all entries to the location list, keeping the previous entries. + + + actions.smart_send_to_qflist() *actions.smart_send_to_qflist()* Sends the selected entries to the quickfix list, replacing the previous entries. If no entry was selected, sends all entries. @@ -325,11 +347,28 @@ actions.smart_add_to_qflist() *actions.smart_add_to_qflist()* +actions.smart_send_to_loclist() *actions.smart_send_to_loclist()* + Sends the selected entries to the location list, replacing the previous + entries. If no entry was selected, sends all entries. + + + +actions.smart_add_to_loclist() *actions.smart_add_to_loclist()* + Adds the selected entries to the location list, keeping the previous + entries. If no entry was selected, adds all entries. + + + actions.open_qflist() *actions.open_qflist()* Open the quickfix list +actions.open_loclist() *actions.open_loclist()* + Open the location list + + + ================================================================================ *telescope.builtin* 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. -- ==================================================