From 9f7caed2832a63fc00f9bdfc71f3f846d1fa12cb Mon Sep 17 00:00:00 2001 From: Johann Nunez Garcia Date: Sun, 4 Apr 2021 16:38:11 -0500 Subject: [PATCH] feat: add option to show indexes in bufferline --- lua/hardline.lua | 6 ++++-- lua/hardline/bufferline.lua | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lua/hardline.lua b/lua/hardline.lua index 95f82e4..740763f 100644 --- a/lua/hardline.lua +++ b/lua/hardline.lua @@ -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 diff --git a/lua/hardline/bufferline.lua b/lua/hardline/bufferline.lua index d99414c..f2749f3 100644 --- a/lua/hardline/bufferline.lua +++ b/lua/hardline/bufferline.lua @@ -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, }