Skip to content

Commit c51a408

Browse files
committed
feat(previewer): script ctx from :verb au/verb map
1 parent e8d0dfc commit c51a408

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

lua/fzf-lua/path.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,10 @@ function M.keymap_to_entry(str)
686686
return { path = info.source:gsub("^@", ""), line = info.linedefined }
687687
end
688688
end
689+
local cmd = ("verb %smap %s"):format(mode, keymap)
690+
local output = vim.split(vim.api.nvim_exec2(cmd, { output = true }).output, "\n")
691+
local file, lnum = (output[#output] or ""):match("Last set from (.-) line (%d+)")
692+
if file and lnum then return { path = vim.fs.normalize(file), line = utils.tointeger(lnum) or 1 } end
689693
-- if entry then return M.entry_to_file(entry, opts) end
690694
return { mode = mode, key = keymap, vmap = vim.inspect(vmap) }
691695
end

lua/fzf-lua/previewer/builtin.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,6 +1879,13 @@ function Previewer.autocmds:parse_entry(entry_str)
18791879
local event, pattern, group, code = unpack(parts, 2)
18801880
content[#content + 1] = "autocmd " .. event .. (pattern ~= "" and (" " .. pattern) or "")
18811881
content[#content + 1] = "\\ " .. code
1882+
local cmd = ("verb au %s %s %s"):format(group, event, pattern)
1883+
local output = vim.split(api.nvim_exec2(cmd, { output = true }).output, "\n")
1884+
local file, lnum = (output[#output] or ""):match("Last set from (.-) line (%d+)")
1885+
if file and lnum then
1886+
self._is_vimL_command = false
1887+
return { path = vim.fs.normalize(file), line = utils.tointeger(lnum) or 1 }
1888+
end
18821889
if group ~= "" then
18831890
content = vim.tbl_map(function(s) return (" "):rep(fn.shiftwidth()) .. s end, content)
18841891
table.insert(content, 1, "augroup " .. group)

0 commit comments

Comments
 (0)