In my library plugin, I have a :Project ls
feature that lists only the files that belongs to the current project as :ls
would have listed them.
The related (GPL w/ exception) code looks is the following:
function! s:As_ls(bid) abort " {{{2
let name = bufname(a:bid)
if empty(name)
let name = 'Used to be known as: '.lh#project#__buffer(a:bid)
endif
return printf('%3d%s %s'
\ , a:bid
\ , (buflisted(a:bid) ? ' ' : 'u')
\ . (bufnr('%') == a:bid ? '%' : bufnr('#') == a:bid ? '#' : ' ')
\ . (! bufloaded(a:bid) ? ' ' : bufwinnr(a:bid)<0 ? 'h' : 'a')
\ . (! getbufvar(a:bid, "&modifiable") ? '-' : getbufvar(a:bid, "&readonly") ? '=' : ' ')
\ . (getbufvar(a:bid, "&modified") ? '+' : ' ')
\ , '"'.name.'"')
endfunction
function! s:ls_project(prj) abort " {{{2
if lh#option#is_unset(a:prj)
echo '(no project specified!)'
endif
let lines = map(copy(a:prj.buffers), 's:As_ls(v:val)')
echo "Buffer list of ".get(a:prj, 'name', '(unnamed)')." project:"
echo join(lines, "\n")
endfunction
Instead of a:prj.buffers
, you would have the list of buffers in range(1, bufnr('$'))
. It would then need to be filtered to keep only the existing buffers (filter(range(1, bufnr('$')), 'bufexists(v:val)')
).
Then you could wrap the call to bufname()
with fnamemodify()
to display exactly what you need.