On Mon 13-Nov-06 7:54pm -0600, Eggum, DavidX S wrote:
> Okay, try this, Matt (it is, again, lightly tested). Granted, it > recalculates from scratch every time, but it only does it when it needs > to and it should still be pretty fast. It also doesn't rely on the > events to be called once every time a buffer is added or deleted. HTH. > > set rulerformat=%60(%=%{GetBufCount()}%) > autocmd VimEnter,BufAdd,BufDelete * call UpdateBufCount() > > let s:prev_last = 0 > let s:prev_count = 0 > > function! UpdateBufCount() > let lst = range(1, bufnr('$')) > call filter(lst, 'buflisted(v:val)') > let s:prev_count = len(lst) > endfunction > > function! GetBufCount() > return s:prev_count > endfunction Using filter() speeds things up quite a bit - very nice. Testing with 78 buffers and running 1,000 times (and dividing the resulting time by 1,000): Using for loop: 3.5 ms Using filter(): .55 ms On one line: .50 ms Using a global variable, instead of global functions, and using a one liner: ==================================================================== let bcnt = 0 function! s:CntBufListed() let g:bcnt = len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) endfunction autocmd VimEnter,BufAdd,BufDelete * call <SID>CntBufListed() ==================================================================== Then the %{GetBufCount()} can be replaced by %{bcnt} Although the function works fine, it still doesn't get triggered when it should. For example, given two files foo and bar in the current directory (listed buffer counts are from my statusline): gvim foo 1 listed buffer :sp bar 2 listed buffers :bd 2 listed buffers :-( :doau BufDelete 1 listed buffer -- Best regards, Bill