From 17f42131650861509878f2a208d09196bbe86645 Mon Sep 17 00:00:00 2001 From: Olivier Roques Date: Mon, 28 Dec 2020 16:55:23 +0100 Subject: [PATCH] Clean up --- lua/hardline.lua | 8 ++++---- lua/hardline/bufferline.lua | 5 ++--- lua/hardline/statusline.lua | 10 ++++------ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lua/hardline.lua b/lua/hardline.lua index a983487..f307b7f 100644 --- a/lua/hardline.lua +++ b/lua/hardline.lua @@ -3,7 +3,7 @@ -- github.com/ojroques -------------------- VARIABLES ----------------------------- -local api, cmd, fn, vim = vim.api, vim.cmd, vim.fn, vim +local api, cmd, vim = vim.api, vim.cmd, vim local g, o, wo = vim.g, vim.o, vim.wo local common = require('hardline.common') local statusline = require('hardline.statusline') @@ -48,11 +48,11 @@ end function M.update_bufferline() local sections = {} local buffers = bufferline.get_buffers() - for _, buffer in ipairs(buffers) do + local separator = {class = 'bufferline', item = '|', conceal = true} + for i, buffer in ipairs(buffers) do table.insert(sections, bufferline.to_section(buffer)) - table.insert(sections, {class = 'bufferline', item = '|', conceal = true}) + if i < #buffers then table.insert(sections, separator) end end - table.remove(sections) return table.concat(vim.tbl_map(common.color, sections)) end diff --git a/lua/hardline/bufferline.lua b/lua/hardline/bufferline.lua index 85b7437..b4a6ccb 100644 --- a/lua/hardline/bufferline.lua +++ b/lua/hardline/bufferline.lua @@ -37,13 +37,12 @@ local function to_section(buffer) if buffer.flags.readonly then table.insert(flags, '[RO]') end flags = table.concat(flags) item = flags == '' and item or string.format('%s %s', item, flags) - local section = { + return { class = 'bufferline', item = string.format(' %s ', item), modified = buffer.flags.modified, current = buffer.current, } - return section end local function get_buffers() @@ -53,12 +52,12 @@ local function get_buffers() table.insert(buffers, { bufnr = nr, name = fn.fnamemodify(fn.bufname(nr), ':t'), + current = nr == fn.bufnr('%'), flags = { modified = fn.getbufvar(nr, '&modified') == 1, modifiable = fn.getbufvar(nr, '&modifiable') == 1, readonly = fn.getbufvar(nr, '&readonly') == 1, }, - current = nr == fn.bufnr('%'), }) end end diff --git a/lua/hardline/statusline.lua b/lua/hardline/statusline.lua index f312b29..1f69a39 100644 --- a/lua/hardline/statusline.lua +++ b/lua/hardline/statusline.lua @@ -26,9 +26,9 @@ local function aggregate_sections(sections) end local function remove_empty_sections(sections) - local function filter(section) - if type(section) == 'table' then return section.item ~= '' end - return section ~= '' + local filter = function(s) + if type(s) == 'table' then return s.item ~= '' end + return s ~= '' end return vim.tbl_filter(filter, sections) end @@ -53,9 +53,7 @@ local function reload_sections(sections) end local function remove_hidden_sections(sections) - local function filter(section) - return not section.hide or section.hide <= fn.winwidth(0) - end + local filter = function(s) return not s.hide or s.hide <= fn.winwidth(0) end return vim.tbl_filter(filter, sections) end