Skip to content

Instantly share code, notes, and snippets.

@LemonBoy
Last active September 29, 2017 08:40
Show Gist options
  • Save LemonBoy/b53eae5188e4ac3ab5b96b2c9a7cf414 to your computer and use it in GitHub Desktop.
Save LemonBoy/b53eae5188e4ac3ab5b96b2c9a7cf414 to your computer and use it in GitHub Desktop.
func! Format(this, alt, _, what) abort
let flags = ' +'[a:what.changed]
\ . ' %'[a:what.bufnr == a:this]
\ . ' #'[a:what.bufnr == a:alt]
let name = empty(a:what.name) ?
\ '[No Name]' : fnamemodify(a:what.name, ':~:.')
return printf(" %2d %s %s", a:what.bufnr, flags, name)
endfunc
func! Sort(a, b) abort
return a:a.bufnr < a:b.bufnr
endfunc
func! DoList() abort
let buf_info = getbufinfo({'buflisted': 1, 'bufloaded': 1})
let by_ext = {}
let res = ''
" divide in buckets
for buf in buf_info
" gather as many extensions as possible
let ext = fnamemodify(buf.name, ':e:e:e')
if empty(ext)
let ext = get(buf.variables, 'current_syntax', 'plain')
endif
let by_ext[ext] = add(get(by_ext, ext, []), buf)
endfor
let Fn = function('Format', [bufnr(''), bufnr('#')])
for key in sort(keys(by_ext))
let bucket = sort(by_ext[key])
let res .= '[' . key . ']:' . "\n"
\ . join(map(bucket, Fn), "\n") . "\n"
endfor
" remove the last '\n'
let res = res[:-2]
echo res
endfunc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment