local fn = vim.fn local function exclude(bufnr) return (fn.buflisted(bufnr) == 0 or fn.getbufvar(bufnr, '&filetype') == 'qf') 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 flags = table.concat(flags) item = flags == '' and item or string.format('%s %s', item, flags) local section = { class = 'bufferline', item = string.format(' %s ', item), modified = buffer.flags.modified, current = buffer.current, } return section end local function get_buffers() local buffers = {} for nr = 1, fn.bufnr('$') do if not exclude(nr) then table.insert(buffers, { bufnr = nr, name = fn.fnamemodify(fn.bufname(nr), ':t'), 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 return buffers end return { to_section = to_section, get_buffers = get_buffers, }