added 'jumps', closes #264

main
bhagwan 2 years ago
parent b2bcca20c2
commit d874e7705a

@ -189,6 +189,7 @@ vim.api.nvim_set_keymap('n', '<c-P>',
| `command_history` | command history |
| `search_history` | search history |
| `marks` | :marks |
| `jumps` | :jumps |
| `registers` | :registers |
| `keymaps` | key mappings |
| `spell_suggest` | spelling suggestions |

@ -219,6 +219,7 @@ MISC *fzf-lua-misc*
| `command_history` | command history |
| `search_history` | search history |
| `marks` | :marks |
| `jumps` | :jumps |
| `registers` | :registers |
| `keymaps` | key mappings |
| `spell_suggest` | spelling suggestions |

@ -277,6 +277,28 @@ M.goto_mark = function(selected)
-- vim.fn.feedkeys(string.format("'%s", mark))
end
M.goto_jump = function(selected, opts)
if opts.jump_using_norm then
local jump, _, _, _ = selected[1]:match("(%d+)%s+(%d+)%s+(%d+)%s+(.*)")
if tonumber(jump) then
vim.cmd(("normal! %d"):format(jump))
end
else
local _, lnum, col, filepath = selected[1]:match("(%d+)%s+(%d+)%s+(%d+)%s+(.*)")
local ok, res = pcall(vim.fn.expand, filepath)
if not ok then filepath = ''
else filepath = res end
if not filepath or not vim.loop.fs_stat(filepath) then
-- no accessible file
-- jump is in current
filepath = vim.api.nvim_buf_get_name(0)
end
local entry = ("%s:%d:%d:"):format(filepath, tonumber(lnum), tonumber(col)+1)
print(entry)
M.file_edit({ entry }, opts)
end
end
M.spell_apply = function(selected)
local word = selected[1]
vim.cmd("normal! ciw" .. word)

@ -443,6 +443,15 @@ M.globals.nvim = {
_ctor = previewers.builtin.marks,
},
},
jumps = {
prompt = 'Jumps> ',
actions = {
["default"] = actions.goto_jump,
},
previewer = {
_ctor = previewers.builtin.jumps,
},
},
commands = {
prompt = 'Commands> ',
actions = {

@ -113,6 +113,7 @@ M.colorschemes = require'fzf-lua.providers.colorschemes'.colorschemes
M.tags = require'fzf-lua.providers.tags'.tags
M.btags = require'fzf-lua.providers.tags'.btags
M.jumps = require'fzf-lua.providers.nvim'.jumps
M.marks = require'fzf-lua.providers.nvim'.marks
M.keymaps = require'fzf-lua.providers.nvim'.keymaps
M.registers = require'fzf-lua.providers.nvim'.registers

@ -593,6 +593,29 @@ function Previewer.marks:parse_entry(entry_str)
}
end
Previewer.jumps = Previewer.buffer_or_file:extend()
function Previewer.jumps:new(o, opts, fzf_win)
Previewer.jumps.super.new(self, o, opts, fzf_win)
return self
end
function Previewer.jumps:parse_entry(entry_str)
local bufnr = nil
local _, lnum, col, filepath = entry_str:match("(%d+)%s+(%d+)%s+(%d+)%s+(.*)")
if filepath and #filepath>0 and not vim.loop.fs_stat(filepath) then
-- file is not accessible,
-- text is a string from current buffer
bufnr = self.win.src_bufnr
filepath = vim.api.nvim_buf_get_name(self.win.src_bufnr)
end
return {
bufnr = bufnr,
path = filepath,
line = tonumber(lnum) or 1,
col = tonumber(col)+1 or 1,
}
end
Previewer.tags = Previewer.buffer_or_file:extend()
function Previewer.tags:new(o, opts, fzf_win)

@ -14,6 +14,7 @@ Previewer.builtin.buffer_or_file = function() return require 'fzf-lua.previewer.
Previewer.builtin.help_tags = function() return require 'fzf-lua.previewer.builtin'.help_tags end
Previewer.builtin.man_pages = function() return require 'fzf-lua.previewer.builtin'.man_pages end
Previewer.builtin.marks = function() return require 'fzf-lua.previewer.builtin'.marks end
Previewer.builtin.jumps = function() return require 'fzf-lua.previewer.builtin'.jumps end
Previewer.builtin.tags = function() return require 'fzf-lua.previewer.builtin'.tags end
return Previewer

@ -87,6 +87,36 @@ M.search_history = function(opts)
history(opts, "search")
end
M.jumps = function(opts)
opts = config.normalize_opts(opts, config.globals.nvim.jumps)
if not opts then return end
coroutine.wrap(function ()
local jumps = vim.fn.execute("jumps")
jumps = vim.split(jumps, "\n")
local entries = {}
for i = #jumps-1, 3, -1 do
local jump, line, col, text = jumps[i]:match("(%d+)%s+(%d+)%s+(%d+)%s+(.*)")
if not jump then print(i, jumps[i]) end
table.insert(entries, string.format("%-15s %-15s %-15s %s",
utils.ansi_codes.yellow(jump),
utils.ansi_codes.blue(line),
utils.ansi_codes.green(col),
text))
end
opts.fzf_opts['--no-multi'] = ''
local selected = core.fzf(opts, entries)
if not selected then return end
actions.act(opts.actions, selected, opts)
end)()
end
M.marks = function(opts)
opts = config.normalize_opts(opts, config.globals.nvim.marks)
if not opts then return end

Loading…
Cancel
Save