Custom buffer picker not closing fzf-lua process #2277
Answered
by
Emille1723
Emille1723
asked this question in
Q&A
-
This gif shows the header and the list data not updating after selecting a different file to edit This gif shows that the header and data only update after using fzf.files which is closing its process properly after a file is selected I have a custom picker that gets its list from this block local currBuf = vim.api.nvim_get_current_buf()
local function list_all_buffers()
-- local bufs = vim.api.nvim_list_bufs()
local bufs = loadedBufs
local listed_bufs = {}
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if
vim.fn.buflisted(buf) == 1
and vim.api.nvim_buf_is_valid(buf)
-- this was causing some problems with not showing some saved buffers in sessions
-- and vim.api.nvim_buf_is_loaded(buf)
and currBuf ~= buf
then
table.insert(listed_bufs, buf)
end
end
Buffers = listed_bufs
return listed_bufs
end
for _, bufid in ipairs(all_bufs) do
local bufInfo = vim.fn.getbufinfo(bufid)
for _, b in ipairs(bufInfo) do
-- next steps
-- extract the name
-- split into, cwd, rel path & name
-- store bufid/bufnr
-- add a check to see if the file is modified
-- add custom modified indicator
local file_path = b["name"]
local bufnr = b["bufnr"]
local file_name = vim.fn.fnamemodify(file_path, ":t")
local file_type = vim.api.nvim_get_option_value("filetype", { buf = bufnr })
local iconRef, file_color = webDevIcons.get_icon_color_by_filetype(file_type) -- fetch icon, colour by filetype
local path_wo_cwd = file_path:gsub(cwd, ''):gsub("^/", '')
local rel_path_wo_file_name = path_wo_cwd:match("(.*/)"):gsub("/$", '') -- print everything before the last / including the last /
local is_modded = vim.api.nvim_get_option_value("modified", { buf = bufnr }) and " " .. icons.fileState.modified or ''
local line_number = vim.api.nvim__buf_stats(bufnr).current_lnum
local entry = string.format("%s |%s |%s%s%s %s%s%s %s %s%s%s%s:%s%s%s%s",
file_path,
bufnr,
navajo_white, is_modded, RESET,
helpers.hex_to_ansi(file_color or "#ffffff"), iconRef, RESET,
file_name,
ITALIC, periwinkle, rel_path_wo_file_name, RESET,
white, RESET,
pastelGreen, line_number, RESET)
table.insert(bufs_data, entry)
end
end Here's the fzf_exec return fzf_lua.fzf_exec(
-- function(fzf_cb)
-- for _, line in ipairs(Buffers) do
-- fzf_cb(line)
-- end
-- fzf_cb(nil)
-- end,
Buffers,
{
actions = {
false,
["enter"] =
-- fn = function(selected, optss)
function(selected, optss)
local entry = selected[1]
if not entry then return end
-- local bpath = entry:gsub("(|.*)", ""):gsub('^%s*(.-)%s*$', '%1') -- remove everything after the first |
local bpath = entry:match("^(.-)%s*|")
-- bpath = vim.fn.trim(bpath)
bpath = vim.fn.expand(vim.fn.trim(bpath))
if vim.fn.filereadable(bpath) == 1 then
-- actions.file_edit({bpath}, optss)
return require("fzf-lua.actions").file_edit({ bpath }, optss)
-- require'fzf-lua'.actions.file_edit({bpath}, optss)
-- return vim.cmd("e " .. bpath)
-- return vim.cmd("silent! e! " .. bpath)
-- vim.cmd("edit " .. vim.fn.fnameescape(bpath))
end
end
,
["ctrl-x"] = {
fn = function(buf, opts)
buf = buf[1]
local buf_nr = string.match(buf, "%|([^|]+)%|"):gsub('^%s*(.-)%s*$', '%1') -- get everything between 1st and 2nd |
local fallback_nr = 0
local fallback_nr1 = 0
-- we're working with the list we passed to the picker
-- so I want to remove the item from the list as well
for i, buff in ipairs(Buffers) do
local buff_nr = string.match(buff, "%|([^|]+)%|"):gsub('^%s*(.-)%s*$', '%1') -- get everything between 1st and 2nd |
if tonumber(buf_nr) == tonumber(buff_nr) then
table.remove(Buffers, i)
end
end
-- delete the buffer
-- vim.api.nvim_buf_delete(tonumber(buf_nr), { unload = true, force = true })
vim.cmd("silent! bwipeout!" .. buf_nr)
-- close the picker if list is now empty after action
if tonumber(#Buffers) <= 0 then
return vim.api.nvim_input('<C-c>')
end
end,
reload = true
}
},
fzf_opts = {
['--info'] = 'hidden',
['--header'] = string.format(" %s %s%s \n %s%s%s %s%s %s%s | %d",
light_blue, vim.uv.cwd():gsub(os.getenv("HOME"), ''):gsub("^/", ''), RESET,
navajo_white, modified, RESET,
purple, curr_iconRef, currBufName, RESET,
(#Buffers + 1)),
['--algo'] = 'v2',
['--tiebreak'] = 'begin', -- choose the first match inline
['--delimiter'] = '|',
['--with-nth'] = '-1..',
},
cwd = vim.uv.cwd(),
keymap = {
builtin = {
["<C-d>"] = "preview-page-down",
},
fzf = {
["ctrl-d"] = "preview-page-down",
}
}
}) it goes to the file but the picker doesn't close until I use another like builtin files any help is very much appreciated |
Beta Was this translation helpful? Give feedback.
Answered by
Emille1723
Aug 27, 2025
Replies: 1 comment 16 replies
-
Cannot reproduce, you'd better provide a minimal repro. |
Beta Was this translation helpful? Give feedback.
16 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so the current buffer info was not consistent
I fetched it before calling the custom picker and passed that info to it
That did the trick. Thanks alot for your help