added marks builtin previewer

main
bhagwan 3 years ago
parent 0feeb0fdbb
commit 329863d754

@ -231,6 +231,8 @@ require'fzf-lua'.setup {
'ctrl-u:unix-line-discard',
'ctrl-f:half-page-down',
'ctrl-b:half-page-up',
'ctrl-a:beginning-of-line',
'ctrl-e:end-of-line',
'alt-a:toggle-all',
},
--[[ fzf_colors = { -- fzf '--color=' options
@ -447,6 +449,7 @@ require'fzf-lua'.setup {
},
},
-- uncomment to disable the previewer
-- nvim = { marks = { previewer = { _ctor = false } } },
-- helptags = { previewer = { _ctor = false } },
-- manpages = { previewer = { _ctor = false } },
-- uncomment to set dummy win location (help|man bar)
@ -481,7 +484,7 @@ EOF
## TODO
- [x] Add more providers
- [x] ~~Add more providers~~
+ [x] ~~LSP (refs, symbols, etc)~~ (2021-07-20)
+ [x] ~~git commits~~ (2021-08-05)
+ [x] ~~git branches~~ (2021-08-05)
@ -496,7 +499,7 @@ EOF
+ [x] ~~tags~~ (2021-08-15)
- [x] ~~Built-in previewer with treesitter support~~ (2021-08-29)
- [x] ~~Improve previewer for `buffers`~~ (2021-08-29)
- [ ] Add support for `marks` in the builtin previewer
- [x] ~~Add builtin previews for `marks|help_tags|man_pages`~~ (2021-09-09)
- [ ] Add built-in plugin documentation
- [ ] Complete the Wiki

@ -53,6 +53,8 @@ M.globals = {
'ctrl-u:unix-line-discard',
'ctrl-f:half-page-down',
'ctrl-b:half-page-up',
'ctrl-a:beginning-of-line',
'ctrl-e:end-of-line',
'alt-a:toggle-all',
},
preview_border = 'border',
@ -371,6 +373,9 @@ M.globals.nvim = {
actions = {
["default"] = actions.goto_mark,
},
previewer = {
_ctor = previewers.builtin.marks,
},
},
commands = {
prompt = 'Commands> ',

@ -11,6 +11,7 @@ Previewer.base = {}
Previewer.buffer_or_file = {}
Previewer.help_tags = {}
Previewer.man_pages = {}
Previewer.marks = {}
-- signgleton instance used for our keymappings
local _self = nil
@ -295,8 +296,12 @@ function Previewer.buffer_or_file:new(o, opts, fzf_win)
return self
end
function Previewer.buffer_or_file:parse_entry(entry_str)
return path.entry_to_file(entry_str, self.opts.cwd)
end
function Previewer.buffer_or_file:populate_preview_buf(entry_str)
local entry = path.entry_to_file(entry_str, self.opts.cwd)
local entry = self:parse_entry(entry_str)
if entry.bufnr and api.nvim_buf_is_loaded(entry.bufnr) then
-- must convert to number or our backup will have conflicting keys
local bufnr = tonumber(entry.bufnr)
@ -547,4 +552,36 @@ function Previewer.man_pages:parse_entry(entry_str)
-- return require'fzf-lua.providers.manpages'.getmanpage(entry_str)
end
function Previewer.marks:new(o, opts, fzf_win)
self = setmetatable(Previewer.buffer_or_file(o, opts, fzf_win), {
__index = vim.tbl_deep_extend("keep",
self, Previewer.buffer_or_file, Previewer.base
)})
return self
end
function Previewer.marks:parse_entry(entry_str)
local bufnr = nil
local mark, lnum, col, filepath = entry_str:match("(.)%s+(%d+)%s+(%d+)%s+(.*)")
-- try to acquire position from sending buffer
-- if this succeeds (line>0) the mark is inside
local pos = vim.api.nvim_buf_get_mark(self.win.src_bufnr, mark)
if pos and pos[1] > 0 and pos[1] == tonumber(lnum) then
bufnr = self.win.src_bufnr
filepath = api.nvim_buf_get_name(bufnr)
end
if filepath and #filepath>0 then
local ok, res = pcall(vim.fn.expand, filepath)
if not ok then filepath = ''
else filepath = res end
filepath = path.relative(filepath, vim.loop.cwd())
end
return {
bufnr = bufnr,
path = filepath,
line = tonumber(lnum) or 1,
col = tonumber(col) or 1,
}
end
return Previewer

Loading…
Cancel
Save