Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bqf.qfwin.handler): allow to use function as opener #129

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lua/bqf/qfwin/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,18 @@ end

---
---@param close boolean
---@param jumpCmd boolean
---@param jumpCmd string|fun(fname: string)
---@param qwinid number
---@param idx number
function M.open(close, jumpCmd, qwinid, idx)
doEdit(qwinid, idx, close, function(bufnr)
if jumpCmd then
local fname = fn.fnameescape(api.nvim_buf_get_name(bufnr))
if not jumpCmd then
api.nvim_set_current_buf(bufnr)
return
end

local fname = fn.fnameescape(api.nvim_buf_get_name(bufnr))
if type(jumpCmd) == 'string' then
if jumpCmd == 'drop' then
local bufInfo = fn.getbufinfo(bufnr)
if fname == '' or #bufInfo == 1 and #bufInfo[1].windows == 0 then
Expand All @@ -242,8 +247,8 @@ function M.open(close, jumpCmd, qwinid, idx)
end
end
cmd(('%s %s'):format(jumpCmd, fname))
else
api.nvim_set_current_buf(bufnr)
elseif type(jumpCmd) == 'function' then
pcall(jumpCmd, fname)
end
end)
end
Expand Down