diff --git a/README.md b/README.md index cf558a1..168fb35 100644 --- a/README.md +++ b/README.md @@ -279,6 +279,7 @@ Built-in functions. Ready to be bound to any key you like. | `builtin.marks` | Lists vim marks and their value | | `builtin.colorscheme` | Lists available colorschemes and applies them on `` | | `builtin.quickfix` | Lists items in the quickfix list | +| `builtin.quickfixhistory` | Lists all quickfix lists in your history and open them with `builtin.quickfix` | | `builtin.loclist` | Lists items from the current window's location list | | `builtin.jumplist` | Lists Jump List entries | | `builtin.vim_options` | Lists vim options, allows you to edit the current value on `` | diff --git a/doc/telescope.txt b/doc/telescope.txt index 1adb7e2..ee1f023 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1117,6 +1117,17 @@ builtin.quickfix({opts}) *telescope.builtin.quickfix()* Options: ~ {ignore_filename} (boolean) dont show filenames (default: true) {trim_text} (boolean) trim results text (default: false) + {nr} (number) specify the quickfix list number + + +builtin.quickfixhistory({opts}) *telescope.builtin.quickfixhistory()* + Lists all quickfix lists in your history and open them with + `builtin.quickfix`. It seems that neovim only keeps the full history for 10 + lists + + + Parameters: ~ + {opts} (table) options to pass to the picker builtin.loclist({opts}) *telescope.builtin.loclist()* diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index 5899629..11b46a2 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -794,12 +794,15 @@ local send_selected_to_qf = function(prompt_bufnr, mode, target) table.insert(qf_entries, entry_to_qf(entry)) end + local prompt = picker:_get_prompt() actions.close(prompt_bufnr) if target == "loclist" then vim.fn.setloclist(picker.original_win_id, qf_entries, mode) else + local qf_title = string.format([[%s (%s)]], picker.prompt_title, prompt) vim.fn.setqflist(qf_entries, mode) + vim.fn.setqflist({}, "a", { title = qf_title }) end end @@ -812,12 +815,15 @@ local send_all_to_qf = function(prompt_bufnr, mode, target) table.insert(qf_entries, entry_to_qf(entry)) end + local prompt = picker:_get_prompt() actions.close(prompt_bufnr) if target == "loclist" then vim.fn.setloclist(picker.original_win_id, qf_entries, mode) else vim.fn.setqflist(qf_entries, mode) + local qf_title = string.format([[%s (%s)]], picker.prompt_title, prompt) + vim.fn.setqflist({}, "a", { title = qf_title }) end end diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index b73c970..e8e88e8 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -241,8 +241,14 @@ builtin.commands = require_on_exported_call("telescope.builtin.internal").comman ---@param opts table: options to pass to the picker ---@field ignore_filename boolean: dont show filenames (default: true) ---@field trim_text boolean: trim results text (default: false) +---@field nr number: specify the quickfix list number builtin.quickfix = require_on_exported_call("telescope.builtin.internal").quickfix +--- Lists all quickfix lists in your history and open them with `builtin.quickfix`. It seems that neovim +--- only keeps the full history for 10 lists +---@param opts table: options to pass to the picker +builtin.quickfixhistory = require_on_exported_call("telescope.builtin.internal").quickfixhistory + --- Lists items from the current window's location list, jumps to location on `` ---@param opts table: options to pass to the picker ---@field ignore_filename boolean: dont show filenames (default: true) diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 122827f..be244cc 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -359,7 +359,8 @@ internal.commands = function(opts) end internal.quickfix = function(opts) - local locations = vim.fn.getqflist() + local qf_identifier = opts.id or vim.F.if_nil(opts.nr, "$") + local locations = vim.fn.getqflist({ [opts.id and "id" or "nr"] = qf_identifier, items = true }).items if vim.tbl_isempty(locations) then return @@ -376,6 +377,65 @@ internal.quickfix = function(opts) }):find() end +internal.quickfixhistory = function(opts) + local qflists = {} + for i = 1, 10 do -- (n)vim keeps at most 10 quickfix lists in full + -- qf weirdness: id = 0 gets id of quickfix list nr + local qflist = vim.fn.getqflist { nr = i, id = 0, title = true, items = true } + if not vim.tbl_isempty(qflist.items) then + table.insert(qflists, qflist) + end + end + local entry_maker = opts.make_entry + or function(entry) + return { + value = entry.title or "Untitled", + ordinal = entry.title or "Untitled", + display = entry.title or "Untitled", + nr = entry.nr, + id = entry.id, + items = entry.items, + } + end + local qf_entry_maker = make_entry.gen_from_quickfix(opts) + pickers.new(opts, { + prompt_title = "Quickfix History", + finder = finders.new_table { + results = qflists, + entry_maker = entry_maker, + }, + previewer = previewers.new_buffer_previewer { + title = "Quickfix List Preview", + dyn_title = function(_, entry) + return entry.title + end, + + get_buffer_by_name = function(_, entry) + return "quickfixlist_" .. tostring(entry.nr) + end, + + define_preview = function(self, entry) + if self.state.bufname then + return + end + local entries = vim.tbl_map(function(i) + return qf_entry_maker(i):display() + end, entry.items) + vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, entries) + end, + }, + sorter = conf.generic_sorter(opts), + attach_mappings = function(_, _) + action_set.select:replace(function(prompt_bufnr) + local nr = action_state.get_selected_entry().nr + actions.close(prompt_bufnr) + internal.quickfix { nr = nr } + end) + return true + end, + }):find() +end + internal.loclist = function(opts) local locations = vim.fn.getloclist(0) local filenames = {}