bairui

getbufferllist

Sep 23rd, 2011
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 0.84 KB | None | 0 0
  1. function! SortByCurrent(b1, b2)
  2.   return a:b1['current'] == a:b2['current'] ? 0 : a:b1['current'] < a:b2['current'] ? 1 : -1
  3. endfunction
  4. function! SortByAlternate(b1, b2)
  5.   return a:b1['alternate'] == a:b2['alternate'] ? 0 : a:b1['alternate'] < a:b2['alternate'] ? 1 : -1
  6. endfunction
  7. function! GetBufferList()
  8.   redir =>bufliststr
  9.   silent! ls
  10.   redir END
  11.   let bufferlist = map(map(split(bufliststr, '\n'), 'split(v:val, "\\s\\+")'),
  12.         \ '{"number": v:val[0], "line": v:val[4], "name": v:val[2], "current": v:val[1] =~ "%", "alternate": v:val[1] =~ "#", "hidden": v:val[1] =~ "h"}')
  13.   let current = sort(copy(bufferlist), 'SortByCurrent')[0]['number']
  14.   let alternate = sort(copy(bufferlist), 'SortByAlternate')[0]['number']
  15.   return {'list': bufferlist, 'current': current, 'alternate': alternate}
  16. endfunction
  17.  
  18. echo GetBufferList()
Advertisement
Add Comment
Please, Sign In to add comment