feat: add option to show indexes in bufferline
This commit is contained in:
committed by
Olivier Roques
parent
4373b556c2
commit
9f7caed283
@@ -16,6 +16,7 @@ M.options = {
|
||||
bufferline = false,
|
||||
bufferline_settings = {
|
||||
exclude_terminal = false,
|
||||
show_index = false,
|
||||
},
|
||||
theme = 'default',
|
||||
sections = {
|
||||
@@ -153,10 +154,11 @@ end
|
||||
-------------------- BUFFERLINE ----------------------------
|
||||
function M.update_bufferline()
|
||||
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 = '|'
|
||||
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
|
||||
table.insert(sections, separator)
|
||||
end
|
||||
|
||||
@@ -40,7 +40,7 @@ local function unique_tail(buffers)
|
||||
unique_tail(buffers)
|
||||
end
|
||||
|
||||
local function to_section(buffer)
|
||||
local function to_section(buffer, idx, settings)
|
||||
local flags = {}
|
||||
local item = buffer.name == '' and '[No Name]' or buffer.name
|
||||
if buffer.flags.modified then
|
||||
@@ -54,9 +54,14 @@ local function to_section(buffer)
|
||||
end
|
||||
flags = table.concat(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 {
|
||||
class = 'bufferline',
|
||||
item = fmt(' %s ', item),
|
||||
item = item,
|
||||
modified = buffer.flags.modified,
|
||||
current = buffer.current,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user