lines with 'set nohidden' to show unloaded buffers (closes issue #159)

main
bhagwan 3 years ago
parent 7243918bdd
commit 9a24d8e466

@ -316,6 +316,12 @@ function Previewer.buffer_or_file:populate_preview_buf(entry_str)
self.preview_bufnr = bufnr
self:preview_buf_post(entry)
else
if entry.bufnr then
-- buffer was unloaded, can happen when calling `lines`
-- with `set nohidden`, fix entry.path since it contains
-- filename only
entry.path = path.relative(vim.api.nvim_buf_get_name(entry.bufnr), vim.loop.cwd())
end
-- mark the buffer for unloading the next call
self.preview_bufloaded = true
-- make sure the file is readable (or bad entry.path)

@ -214,29 +214,33 @@ M.buffer_lines = function(opts)
local items = {}
for _, bufnr in ipairs(buffers) do
local data = {}
local filepath = api.nvim_buf_get_name(bufnr)
if api.nvim_buf_is_loaded(bufnr) then
local bufname = path.basename(api.nvim_buf_get_name(bufnr))
local data = api.nvim_buf_get_lines(bufnr, 0, -1, false)
local buficon, hl
if opts.file_icons then
local filename = path.tail(bufname)
local extension = path.extension(filename)
buficon, hl = core.get_devicon(filename, extension)
if opts.color_icons then
buficon = utils.ansi_codes[hl](buficon)
end
end
for l, text in ipairs(data) do
table.insert(items, ("[%s]%s%s%s%s:%s: %s"):format(
utils.ansi_codes.yellow(tostring(bufnr)),
utils.nbsp,
buficon or '',
buficon and utils.nbsp or '',
utils.ansi_codes.magenta(#bufname>0 and bufname or "[No Name]"),
utils.ansi_codes.green(tostring(l)),
text))
data = api.nvim_buf_get_lines(bufnr, 0, -1, false)
elseif vim.fn.filereadable(filepath) ~= 0 then
data = vim.fn.readfile(filepath, "")
end
local bufname = path.basename(filepath)
local buficon, hl
if opts.file_icons then
local filename = path.tail(bufname)
local extension = path.extension(filename)
buficon, hl = core.get_devicon(filename, extension)
if opts.color_icons then
buficon = utils.ansi_codes[hl](buficon)
end
end
for l, text in ipairs(data) do
table.insert(items, ("[%s]%s%s%s%s:%s: %s"):format(
utils.ansi_codes.yellow(tostring(bufnr)),
utils.nbsp,
buficon or '',
buficon and utils.nbsp or '',
utils.ansi_codes.magenta(#bufname>0 and bufname or "[No Name]"),
utils.ansi_codes.green(tostring(l)),
text))
end
end
-- ignore bufnr when searching

Loading…
Cancel
Save