feat: jumplist picker and jump to row/col on existing buffers. (#813)
This commit is contained in:
@@ -389,7 +389,8 @@ Built-in functions. Ready to be bound to any key you like. :smile:
|
||||
| `builtin.buffers` | Lists Open buffers in the current vim instance. |
|
||||
| `builtin.oldfiles` | Lists Previously open files. |
|
||||
| `builtin.commands` | Lists Available plugin/user commands and run it. |
|
||||
| `builtin.tags` | Lists Tags in current directory with preview (ctags -R) |
|
||||
| `builtin.tags` | Lists Tags in current directory with preview (ctags -R). |
|
||||
| `builtin.tagstack` | Lists Tagstack entries. |
|
||||
| `builtin.command_history` | Lists Commands previously ran and run it on enter. |
|
||||
| `builtin.search_history` | Lists Searches previously ran and run it on enter. |
|
||||
| `builtin.help_tags` | Lists Available help tags and open help document. |
|
||||
@@ -398,6 +399,7 @@ Built-in functions. Ready to be bound to any key you like. :smile:
|
||||
| `builtin.colorscheme` | Lists Colorscheme and switch to it on enter. |
|
||||
| `builtin.quickfix` | Lists items from quickfix. |
|
||||
| `builtin.loclist` | Lists items from current window's location list. |
|
||||
| `builtin.jumplist` | Lists Jump List entries. |
|
||||
| `builtin.vim_options` | Lists vim options and on enter edit the options value. |
|
||||
| `builtin.registers` | Lists vim registers and edit or paste selection. |
|
||||
| `builtin.autocommands` | Lists vim autocommands and go to their declaration. |
|
||||
|
||||
@@ -113,13 +113,13 @@ action_set.edit = function(prompt_bufnr, command)
|
||||
if entry_bufnr then
|
||||
edit_buffer(command, entry_bufnr)
|
||||
else
|
||||
|
||||
-- check if we didn't pick a different buffer
|
||||
-- prevents restarting lsp server
|
||||
if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then
|
||||
filename = path.normalize(vim.fn.fnameescape(filename), vim.loop.cwd())
|
||||
vim.cmd(string.format("%s %s", command, filename))
|
||||
end
|
||||
end
|
||||
|
||||
if row and col then
|
||||
local ok, err_msg = pcall(a.nvim_win_set_cursor, 0, {row, col})
|
||||
@@ -128,7 +128,6 @@ action_set.edit = function(prompt_bufnr, command)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- Scrolls the previewer up or down
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
|
||||
@@ -63,6 +63,7 @@ builtin.highlights = require('telescope.builtin.internal').highlights
|
||||
builtin.autocommands = require('telescope.builtin.internal').autocommands
|
||||
builtin.spell_suggest = require('telescope.builtin.internal').spell_suggest
|
||||
builtin.tagstack = require('telescope.builtin.internal').tagstack
|
||||
builtin.jumplist = require('telescope.builtin.internal').jumplist
|
||||
|
||||
builtin.lsp_references = require('telescope.builtin.lsp').references
|
||||
builtin.lsp_definitions = require('telescope.builtin.lsp').definitions
|
||||
|
||||
@@ -922,11 +922,32 @@ internal.tagstack = function(opts)
|
||||
results = tags,
|
||||
entry_maker = make_entry.gen_from_quickfix(opts),
|
||||
},
|
||||
previewer = previewers.vim_buffer_qflist.new(opts),
|
||||
previewer = conf.qflist_previewer(opts),
|
||||
sorter = conf.generic_sorter(opts),
|
||||
}):find()
|
||||
end
|
||||
|
||||
internal.jumplist = function(opts)
|
||||
opts = opts or {}
|
||||
local jumplist = vim.fn.getjumplist()[1]
|
||||
|
||||
-- reverse the list
|
||||
local sorted_jumplist = {}
|
||||
for i = #jumplist, 1, -1 do
|
||||
jumplist[i].text = ''
|
||||
table.insert(sorted_jumplist, jumplist[i])
|
||||
end
|
||||
|
||||
pickers.new(opts, {
|
||||
prompt_title = 'Jumplist',
|
||||
finder = finders.new_table {
|
||||
results = sorted_jumplist,
|
||||
entry_maker = make_entry.gen_from_jumplist(opts),
|
||||
},
|
||||
previewer = conf.qflist_previewer(opts),
|
||||
sorter = conf.generic_sorter(opts),
|
||||
}):find()
|
||||
end
|
||||
|
||||
local function apply_checks(mod)
|
||||
for k, v in pairs(mod) do
|
||||
|
||||
@@ -1139,5 +1139,61 @@ function make_entry.gen_from_git_status(opts)
|
||||
end
|
||||
end
|
||||
|
||||
function make_entry.gen_from_jumplist(opts)
|
||||
opts = opts or {}
|
||||
opts.tail_path = get_default(opts.tail_path, true)
|
||||
|
||||
local displayer = entry_display.create {
|
||||
separator = "▏",
|
||||
items = {
|
||||
{ width = 10 },
|
||||
{ remaining = true },
|
||||
}
|
||||
}
|
||||
|
||||
local make_display = function(entry)
|
||||
local filename
|
||||
if not opts.hide_filename then
|
||||
filename = entry.filename
|
||||
if opts.tail_path then
|
||||
filename = utils.path_tail(filename)
|
||||
elseif opts.shorten_path then
|
||||
filename = utils.path_shorten(filename)
|
||||
end
|
||||
end
|
||||
|
||||
local line_info = {table.concat({entry.lnum, entry.col}, ":"), "TelescopeResultsLineNr"}
|
||||
|
||||
return displayer {
|
||||
line_info,
|
||||
filename,
|
||||
}
|
||||
end
|
||||
|
||||
return function(entry)
|
||||
if not vim.api.nvim_buf_is_valid(entry.bufnr) then
|
||||
return
|
||||
end
|
||||
|
||||
local filename = entry.filename or vim.api.nvim_buf_get_name(entry.bufnr)
|
||||
|
||||
return {
|
||||
valid = true,
|
||||
|
||||
value = entry,
|
||||
ordinal = (
|
||||
not opts.ignore_filename and filename
|
||||
or ''
|
||||
) .. ' ' .. entry.text,
|
||||
display = make_display,
|
||||
|
||||
bufnr = entry.bufnr,
|
||||
filename = filename,
|
||||
lnum = entry.lnum,
|
||||
col = entry.col,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return make_entry
|
||||
|
||||
Reference in New Issue
Block a user