This commit is contained in:
Olivier Roques
2020-12-28 16:55:23 +01:00
parent 1076f7f317
commit 17f4213165
3 changed files with 10 additions and 13 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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