summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-10-09 17:33:48 -0400
committerTJ DeVries <devries.timothyj@gmail.com>2020-10-15 22:30:08 -0400
commit5a7a3147a4553146342aeb5a112c72606367fea5 (patch)
tree4e31dcbd41746c011ff681156aa50323ad680cd9
parent18a91f27143628d732ae339b5df3996e3066fdb6 (diff)
fix: Use entry maker for marks
-rw-r--r--lua/telescope/actions.lua2
-rw-r--r--lua/telescope/builtin.lua27
-rw-r--r--lua/telescope/make_entry.lua19
-rw-r--r--lua/telescope/utils.lua32
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', '<CR>', jump_marks)
- map('n', '<CR>', 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