feat: add option to show indexes in bufferline

This commit is contained in:
Johann Nunez Garcia
2021-04-04 16:38:11 -05:00
committed by Olivier Roques
parent 4373b556c2
commit 9f7caed283
2 changed files with 11 additions and 4 deletions

View File

@@ -16,6 +16,7 @@ M.options = {
bufferline = false, bufferline = false,
bufferline_settings = { bufferline_settings = {
exclude_terminal = false, exclude_terminal = false,
show_index = false,
}, },
theme = 'default', theme = 'default',
sections = { sections = {
@@ -153,10 +154,11 @@ end
-------------------- BUFFERLINE ---------------------------- -------------------- BUFFERLINE ----------------------------
function M.update_bufferline() function M.update_bufferline()
local sections = {} local sections = {}
local buffers = bufferline.get_buffers(M.options.bufferline_settings) local settings = M.options.bufferline_settings
local buffers = bufferline.get_buffers(settings)
local separator = '|' local separator = '|'
for i, buffer in ipairs(buffers) do for i, buffer in ipairs(buffers) do
table.insert(sections, bufferline.to_section(buffer)) table.insert(sections, bufferline.to_section(buffer, i, settings))
if i < #buffers then if i < #buffers then
table.insert(sections, separator) table.insert(sections, separator)
end end

View File

@@ -40,7 +40,7 @@ local function unique_tail(buffers)
unique_tail(buffers) unique_tail(buffers)
end end
local function to_section(buffer) local function to_section(buffer, idx, settings)
local flags = {} local flags = {}
local item = buffer.name == '' and '[No Name]' or buffer.name local item = buffer.name == '' and '[No Name]' or buffer.name
if buffer.flags.modified then if buffer.flags.modified then
@@ -54,9 +54,14 @@ local function to_section(buffer)
end end
flags = table.concat(flags) flags = table.concat(flags)
item = flags == '' and item or fmt('%s %s', item, flags) item = flags == '' and item or fmt('%s %s', item, flags)
if settings.show_index then
item = fmt(' %d:%s ', idx, item)
else
item = fmt(' %s ', item)
end
return { return {
class = 'bufferline', class = 'bufferline',
item = fmt(' %s ', item), item = item,
modified = buffer.flags.modified, modified = buffer.flags.modified,
current = buffer.current, current = buffer.current,
} }