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.buffers` | Lists Open buffers in the current vim instance. |
|
||||||
| `builtin.oldfiles` | Lists Previously open files. |
|
| `builtin.oldfiles` | Lists Previously open files. |
|
||||||
| `builtin.commands` | Lists Available plugin/user commands and run it. |
|
| `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.command_history` | Lists Commands previously ran and run it on enter. |
|
||||||
| `builtin.search_history` | Lists Searches 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. |
|
| `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.colorscheme` | Lists Colorscheme and switch to it on enter. |
|
||||||
| `builtin.quickfix` | Lists items from quickfix. |
|
| `builtin.quickfix` | Lists items from quickfix. |
|
||||||
| `builtin.loclist` | Lists items from current window's location list. |
|
| `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.vim_options` | Lists vim options and on enter edit the options value. |
|
||||||
| `builtin.registers` | Lists vim registers and edit or paste selection. |
|
| `builtin.registers` | Lists vim registers and edit or paste selection. |
|
||||||
| `builtin.autocommands` | Lists vim autocommands and go to their declaration. |
|
| `builtin.autocommands` | Lists vim autocommands and go to their declaration. |
|
||||||
|
|||||||
@@ -113,19 +113,18 @@ action_set.edit = function(prompt_bufnr, command)
|
|||||||
if entry_bufnr then
|
if entry_bufnr then
|
||||||
edit_buffer(command, entry_bufnr)
|
edit_buffer(command, entry_bufnr)
|
||||||
else
|
else
|
||||||
|
|
||||||
-- check if we didn't pick a different buffer
|
-- check if we didn't pick a different buffer
|
||||||
-- prevents restarting lsp server
|
-- prevents restarting lsp server
|
||||||
if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then
|
if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then
|
||||||
filename = path.normalize(vim.fn.fnameescape(filename), vim.loop.cwd())
|
filename = path.normalize(vim.fn.fnameescape(filename), vim.loop.cwd())
|
||||||
vim.cmd(string.format("%s %s", command, filename))
|
vim.cmd(string.format("%s %s", command, filename))
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if row and col then
|
if row and col then
|
||||||
local ok, err_msg = pcall(a.nvim_win_set_cursor, 0, {row, col})
|
local ok, err_msg = pcall(a.nvim_win_set_cursor, 0, {row, col})
|
||||||
if not ok then
|
if not ok then
|
||||||
log.debug("Failed to move to cursor:", err_msg, row, col)
|
log.debug("Failed to move to cursor:", err_msg, row, col)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ builtin.highlights = require('telescope.builtin.internal').highlights
|
|||||||
builtin.autocommands = require('telescope.builtin.internal').autocommands
|
builtin.autocommands = require('telescope.builtin.internal').autocommands
|
||||||
builtin.spell_suggest = require('telescope.builtin.internal').spell_suggest
|
builtin.spell_suggest = require('telescope.builtin.internal').spell_suggest
|
||||||
builtin.tagstack = require('telescope.builtin.internal').tagstack
|
builtin.tagstack = require('telescope.builtin.internal').tagstack
|
||||||
|
builtin.jumplist = require('telescope.builtin.internal').jumplist
|
||||||
|
|
||||||
builtin.lsp_references = require('telescope.builtin.lsp').references
|
builtin.lsp_references = require('telescope.builtin.lsp').references
|
||||||
builtin.lsp_definitions = require('telescope.builtin.lsp').definitions
|
builtin.lsp_definitions = require('telescope.builtin.lsp').definitions
|
||||||
|
|||||||
@@ -917,16 +917,37 @@ internal.tagstack = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
pickers.new(opts, {
|
pickers.new(opts, {
|
||||||
prompt_title = 'TagStack',
|
prompt_title = 'TagStack',
|
||||||
finder = finders.new_table {
|
finder = finders.new_table {
|
||||||
results = tags,
|
results = tags,
|
||||||
entry_maker = make_entry.gen_from_quickfix(opts),
|
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),
|
sorter = conf.generic_sorter(opts),
|
||||||
}):find()
|
}):find()
|
||||||
end
|
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)
|
local function apply_checks(mod)
|
||||||
for k, v in pairs(mod) do
|
for k, v in pairs(mod) do
|
||||||
|
|||||||
@@ -1139,5 +1139,61 @@ function make_entry.gen_from_git_status(opts)
|
|||||||
end
|
end
|
||||||
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
|
return make_entry
|
||||||
|
|||||||
Reference in New Issue
Block a user