From 5a7a3147a4553146342aeb5a112c72606367fea5 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Fri, 9 Oct 2020 17:33:48 -0400 Subject: [PATCH] fix: Use entry maker for marks --- lua/telescope/actions.lua | 2 +- lua/telescope/builtin.lua | 27 ++++++--------------------- lua/telescope/make_entry.lua | 19 +++++++++++++++++++ lua/telescope/utils.lua | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/lua/telescope/actions.lua b/lua/telescope/actions.lua index 4b15c93..ebebbea 100644 --- a/lua/telescope/actions.lua +++ b/lua/telescope/actions.lua @@ -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 diff --git a/lua/telescope/builtin.lua b/lua/telescope/builtin.lua index 0973bdb..06fc874 100644 --- a/lua/telescope/builtin.lua +++ b/lua/telescope/builtin.lua @@ -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', '', jump_marks) - map('n', '', jump_marks) - - return true - end }):find() end diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 891d4af..e765904 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -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 diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 9d948ce..58d8183 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -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