Created
September 23, 2017 11:44
-
-
Save LemonBoy/c99217da1607e4a0ffba613caa315c68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func! Format(_, what) abort | |
let flags = ' +'[a:what.changed] | |
\ . ' %'[a:what.bufnr == bufnr('')] | |
\ . ' #'[a:what.bufnr == bufnr('#')] | |
if empty(a:what.name) | |
let name = '[No Name]' | |
else | |
let name = fnamemodify(a:what.name, ':~:.') | |
endif | |
return printf(" %2d %s %s", a:what.bufnr, flags, name) | |
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 | |
let ext = fnamemodify(buf.name, ':e') | |
if empty(ext) | |
let ext = get(buf.variables, 'current_syntax', 'xxx') | |
endif | |
let by_ext[ext] = add(get(by_ext, ext, []), buf) | |
endfor | |
for key in sort(keys(by_ext)) | |
let res .= '[' . key . ']:' . "\n" | |
let res .= join(map(by_ext[key], function('Format')), "\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