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



-----Original Message-----
From: Eggum, DavidX S 
Sent: Monday, November 13, 2006 5:36 PM
To: A.J.Mechelynck
Cc: Matt Zyzik; Yakov Lerner; vim-dev@vim.org
Subject: RE: buffer list count

Thank you for the correction, Tony. If the BufDelete command is called
for each of the deleted buffers then the proposed solution will still
work. 

*crossing fingers*

-----Original Message-----
From: A.J.Mechelynck [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 13, 2006 5:05 PM
To: Eggum, DavidX S
Cc: Matt Zyzik; Yakov Lerner; vim-dev@vim.org
Subject: Re: buffer list count

Eggum, DavidX S wrote:
> Matt,
> 
> You can speed up the calculations considerably if you keep several
> things in mind:
> - buffer numbers are never reused.
> - built-in vim functions are written in C and are very fast
> - although you can open many files at once (like vim *.cs), buffers
are
> usually (always?) deleted one at a time.
[...]

Not always. The :bwipeout and :bdelete commands can take any number of 
space-separated buffer numbers and/or non-purely-numeric buffer names. 
Personally I sometimes use :bw in that way when ":ls!" shows too many
buffers 
for my taste.


Best regards,
Tony.

Reply via email to