diff --git a/README.md b/README.md index 39afff8..2a4860e 100644 --- a/README.md +++ b/README.md @@ -189,6 +189,7 @@ vim.api.nvim_set_keymap('n', '', | `command_history` | command history | | `search_history` | search history | | `marks` | :marks | +| `jumps` | :jumps | | `registers` | :registers | | `keymaps` | key mappings | | `spell_suggest` | spelling suggestions | diff --git a/doc/fzf-lua.txt b/doc/fzf-lua.txt index f33858e..0c49021 100644 --- a/doc/fzf-lua.txt +++ b/doc/fzf-lua.txt @@ -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 | diff --git a/lua/fzf-lua/actions.lua b/lua/fzf-lua/actions.lua index f2171c3..f481816 100644 --- a/lua/fzf-lua/actions.lua +++ b/lua/fzf-lua/actions.lua @@ -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) diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index 55458fd..550b269 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -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 = { diff --git a/lua/fzf-lua/init.lua b/lua/fzf-lua/init.lua index 01f4588..72281f2 100644 --- a/lua/fzf-lua/init.lua +++ b/lua/fzf-lua/init.lua @@ -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 diff --git a/lua/fzf-lua/previewer/builtin.lua b/lua/fzf-lua/previewer/builtin.lua index 0259119..3f13974 100644 --- a/lua/fzf-lua/previewer/builtin.lua +++ b/lua/fzf-lua/previewer/builtin.lua @@ -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) diff --git a/lua/fzf-lua/previewer/init.lua b/lua/fzf-lua/previewer/init.lua index 9e1c441..5cbcb2d 100644 --- a/lua/fzf-lua/previewer/init.lua +++ b/lua/fzf-lua/previewer/init.lua @@ -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 diff --git a/lua/fzf-lua/providers/nvim.lua b/lua/fzf-lua/providers/nvim.lua index fe6f9f5..4626323 100644 --- a/lua/fzf-lua/providers/nvim.lua +++ b/lua/fzf-lua/providers/nvim.lua @@ -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