summaryrefslogtreecommitdiff
path: root/lua/telescope
diff options
context:
space:
mode:
authorpjmtdw <pjmtdw@gmail.com>2022-05-16 05:00:01 +0900
committerGitHub <noreply@github.com>2022-05-15 22:00:01 +0200
commit2e421ef02dd1acf596d6c382d27230381a946b47 (patch)
tree2f48a09418f161bac25d33109ba80982a4f6b27f /lua/telescope
parent20040cac31aac7cd41fc255178cf3f1351993359 (diff)
fix: get mark list from opts.bufnr instead of using :marks (#1935)
Should fix marks when going through builtin.builtin
Diffstat (limited to 'lua/telescope')
-rw-r--r--lua/telescope/builtin/internal.lua44
-rw-r--r--lua/telescope/make_entry.lua21
2 files changed, 47 insertions, 18 deletions
diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua
index be244cc..e0dc9b9 100644
--- a/lua/telescope/builtin/internal.lua
+++ b/lua/telescope/builtin/internal.lua
@@ -993,11 +993,45 @@ internal.colorscheme = function(opts)
end
internal.marks = function(opts)
- local marks = vim.api.nvim_exec("marks", true)
- local marks_table = vim.fn.split(marks, "\n")
-
- -- Pop off the header.
- table.remove(marks_table, 1)
+ local local_marks = {
+ items = vim.fn.getmarklist(opts.bufnr),
+ name_func = function(_, line)
+ return vim.api.nvim_buf_get_lines(opts.bufnr, line - 1, line, false)[1]
+ end,
+ }
+ local global_marks = {
+ items = vim.fn.getmarklist(),
+ name_func = function(mark, _)
+ -- get buffer name if it is opened, otherwise get file name
+ return vim.api.nvim_get_mark(mark, {})[4]
+ end,
+ }
+ local marks_table = {}
+ local marks_others = {}
+ local bufname = vim.api.nvim_buf_get_name(opts.bufnr)
+ for _, cnf in ipairs { local_marks, global_marks } do
+ for _, v in ipairs(cnf.items) do
+ -- strip the first single quote character
+ local mark = string.sub(v.mark, 2, 3)
+ local _, lnum, col, _ = unpack(v.pos)
+ local name = cnf.name_func(mark, lnum)
+ -- same format to :marks command
+ local line = string.format("%s %6d %4d %s", mark, lnum, col - 1, name)
+ local row = {
+ line = line,
+ lnum = lnum,
+ col = col,
+ filename = v.file or bufname,
+ }
+ -- non alphanumeric marks goes to last
+ if mark:match "%w" then
+ table.insert(marks_table, row)
+ else
+ table.insert(marks_others, row)
+ end
+ end
+ end
+ marks_table = vim.fn.extend(marks_table, marks_others)
pickers.new(opts, {
prompt_title = "Marks",
diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua
index 5c39c4e..703a00a 100644
--- a/lua/telescope/make_entry.lua
+++ b/lua/telescope/make_entry.lua
@@ -635,20 +635,15 @@ function make_entry.gen_from_apropos(opts)
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 function(item)
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]),
+ value = item.line,
+ ordinal = item.line,
+ display = item.line,
+ lnum = item.lnum,
+ col = item.col,
+ start = item.lnum,
+ filename = item.filename,
}
end
end