feat(picker.buffers): added buftype and filetype for scratch buffers

This commit is contained in:
Folke Lemaitre 2025-10-26 19:23:47 +01:00
parent 597ebd4115
commit 6a132716af
No known key found for this signature in database
GPG key ID: 9B52594D560070AB
3 changed files with 29 additions and 1 deletions

View file

@ -44,6 +44,8 @@ Snacks.util.set_hl({
KeymapNowait = "@variable.builtin",
BufNr = "Number",
BufFlags = "NonText",
BufType = "Function",
FileType = "String",
KeymapRhs = "NonText",
Time = "Special",
UndoAdded = "Added",

View file

@ -58,6 +58,9 @@ function M.filename(item, picker)
local icon, hl = Snacks.util.icon(name, cat, {
fallback = picker.opts.icons.files,
})
if item.buftype == "terminal" then
icon, hl = "", "Special"
end
if item.dir and item.open then
icon = picker.opts.icons.files.dir_open
end
@ -637,7 +640,27 @@ function M.buffer(item, picker)
ret[#ret + 1] = { " " }
ret[#ret + 1] = { Snacks.picker.util.align(item.flags, 2, { align = "right" }), "SnacksPickerBufFlags" }
ret[#ret + 1] = { " " }
vim.list_extend(ret, M.filename(item, picker))
if item.buftype ~= "" then
ret[#ret + 1] = { " " }
vim.list_extend(ret, {
{ "[", "SnacksPickerDelim" },
{ item.buftype, "SnacksPickerBufType" },
{ "]", "SnacksPickerDelim" },
})
end
if item.name == "" and item.filetype ~= "" then
ret[#ret + 1] = { " " }
vim.list_extend(ret, {
{ "[", "SnacksPickerDelim" },
{ item.filetype, "SnacksPickerFileType" },
{ "]", "SnacksPickerDelim" },
})
end
return ret
end

View file

@ -22,7 +22,7 @@ function M.buffers(opts, ctx)
if keep then
local name = vim.api.nvim_buf_get_name(buf)
if name == "" then
name = "[No Name]" .. (vim.bo[buf].filetype ~= "" and " " .. vim.bo[buf].filetype or "")
name = "[Scratch]"
end
local info = vim.fn.getbufinfo(buf)[1]
local mark = vim.api.nvim_buf_get_mark(buf, '"')
@ -35,6 +35,9 @@ function M.buffers(opts, ctx)
table.insert(items, {
flags = table.concat(flags),
buf = buf,
name = vim.api.nvim_buf_get_name(buf),
buftype = vim.bo[buf].buftype,
filetype = vim.bo[buf].filetype,
text = buf .. " " .. name,
file = name,
info = info,