fix: Use entry maker for marks
This commit is contained in:
@@ -110,7 +110,7 @@ local function goto_file_selection(prompt_bufnr, command)
|
||||
if row and col then
|
||||
local ok, err_msg = pcall(a.nvim_win_set_cursor, 0, {row, col})
|
||||
if not ok then
|
||||
log.debug("Failed to move to cursor:", err_msg)
|
||||
log.debug("Failed to move to cursor:", err_msg, row, col)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -807,34 +807,19 @@ builtin.marks = function(opts)
|
||||
opts = opts or {}
|
||||
|
||||
local marks = vim.api.nvim_exec("marks", true)
|
||||
local marks_table = vim.fn.split(marks,'\n')
|
||||
local marks_table = vim.fn.split(marks, "\n")
|
||||
|
||||
-- Pop off the header.
|
||||
table.remove(marks_table, 1)
|
||||
|
||||
pickers.new(opts,{
|
||||
prompt = 'Marks',
|
||||
finder = finders.new_table {
|
||||
results = marks_table,
|
||||
entry_maker = make_entry.gen_from_marks(opts),
|
||||
},
|
||||
previewer = previewers.man.new(opts),
|
||||
previewer = previewers.vimgrep.new(opts),
|
||||
sorter = sorters.get_generic_fuzzy_sorter(),
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
local jump_marks = function()
|
||||
local selection = actions.get_selected_entry(prompt_bufnr)
|
||||
local marks_data = {}
|
||||
for v in selection.value:gmatch("%S+") do
|
||||
table.insert(marks_data,v)
|
||||
end
|
||||
|
||||
local row,col = tonumber(marks_data[2]),tonumber(marks_data[3])
|
||||
actions.close(prompt_bufnr)
|
||||
vim.api.nvim_command("edit "..marks_data[4])
|
||||
vim.api.nvim_win_set_cursor(0,{row,col})
|
||||
end
|
||||
|
||||
map('i', '<CR>', jump_marks)
|
||||
map('n', '<CR>', jump_marks)
|
||||
|
||||
return true
|
||||
end
|
||||
}):find()
|
||||
end
|
||||
|
||||
|
||||
@@ -426,4 +426,23 @@ function make_entry.gen_from_apropos(opts)
|
||||
end
|
||||
end
|
||||
|
||||
function make_entry.gen_from_marks(_)
|
||||
return function(line)
|
||||
local split_value = utils.max_split(line, "%s+", 4)
|
||||
|
||||
local mark_value = split_value[1]
|
||||
local cursor_position = vim.fn.getpos("'" .. mark_value)
|
||||
|
||||
return {
|
||||
value = line,
|
||||
ordinal = line,
|
||||
display = line,
|
||||
lnum = cursor_position[2],
|
||||
col = cursor_position[3],
|
||||
start = cursor_position[2],
|
||||
filename = vim.api.nvim_buf_get_name(cursor_position[1])
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
return make_entry
|
||||
|
||||
@@ -146,4 +146,36 @@ function utils.buf_delete(bufnr)
|
||||
end
|
||||
end
|
||||
|
||||
function utils.max_split(s, pattern, maxsplit)
|
||||
pattern = pattern or ' '
|
||||
maxsplit = maxsplit or -1
|
||||
|
||||
local t = {}
|
||||
|
||||
local curpos = 0
|
||||
while maxsplit ~= 0 and curpos < #s do
|
||||
local found, final = string.find(s, pattern, curpos, false)
|
||||
if found ~= nil then
|
||||
local val = string.sub(s, curpos, found - 1)
|
||||
|
||||
if #val > 0 then
|
||||
maxsplit = maxsplit - 1
|
||||
table.insert(t, val)
|
||||
end
|
||||
|
||||
curpos = final + 1
|
||||
else
|
||||
table.insert(t, string.sub(s, curpos))
|
||||
break
|
||||
-- curpos = curpos + 1
|
||||
end
|
||||
|
||||
if maxsplit == 0 then
|
||||
table.insert(t, string.sub(s, curpos))
|
||||
end
|
||||
end
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
return utils
|
||||
|
||||
Reference in New Issue
Block a user