Improve readability

This commit is contained in:
Olivier Roques
2021-02-08 23:09:35 +01:00
parent 85f37f30a1
commit 18b75356e3
10 changed files with 171 additions and 94 deletions

View File

@@ -1,10 +1,8 @@
local fn, vim = vim.fn, vim
local fmt = string.format
local function exclude(bufnr)
return (
fn.buflisted(bufnr) == 0 or
fn.getbufvar(bufnr, '&filetype') == 'qf'
)
return fn.buflisted(bufnr) == 0 or fn.getbufvar(bufnr, '&filetype') == 'qf'
end
local function get_head(path, tail)
@@ -26,11 +24,13 @@ local function unique_tail(buffers)
end
duplicate = duplicate or hist[buffer.name] > 1
end
if not duplicate then return end
if not duplicate then
return
end
for _, buffer in ipairs(buffers) do
if hist[buffer.name] > 1 then
local parent = get_head(fn.bufname(buffer.bufnr), buffer.name)
buffer.name = string.format('%s/%s', parent, buffer.name)
buffer.name = fmt('%s/%s', parent, buffer.name)
end
end
unique_tail(buffers)
@@ -39,14 +39,20 @@ end
local function to_section(buffer)
local flags = {}
local item = buffer.name == '' and '[No Name]' or buffer.name
if buffer.flags.modified then table.insert(flags, '[+]') end
if not buffer.flags.modifiable then table.insert(flags, '[-]') end
if buffer.flags.readonly then table.insert(flags, '[RO]') end
if buffer.flags.modified then
table.insert(flags, '[+]')
end
if not buffer.flags.modifiable then
table.insert(flags, '[-]')
end
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)
item = flags == '' and item or fmt('%s %s', item, flags)
return {
class = 'bufferline',
item = string.format(' %s ', item),
item = fmt(' %s ', item),
modified = buffer.flags.modified,
current = buffer.current,
}