On Mon, Nov 13, 2006 at 05:54:01PM -0800, Eggum, DavidX S wrote:
> Okay, try this, Matt (it is, again, lightly tested). Granted, it
> [...]
> 
> 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

Ok. I think I've finally settled on the best solution.

Firstly, of these two functions:

        function Try1()
                let lst = range(1, bufnr('$'))
                call filter(lst, 'buflisted(v:val)')
                let g:zbuflistcount = len(lst)
        endfunction

        function Try2()
                let cnt = 0
                for nr in range(1, bufnr("$"))
                        if(buflisted(nr))
                                let cnt += 1
                        endif
                endfor
                let g:zbuflistcount = cnt
        endfunction

Try1 is 3 times faster than Try2 (tested with hundreds of buffers;
called hundreds of times).

So I decided to go with Try1; however, I'm still uncomfortable with it
in the rulerformat; so the final scheme I chose is as follows:

        set rulerformat=%22(%{g:zbuflistcount};%M%n\ %=%l,%c%V\ %P%)
        autocmd BufAdd * let g:zbuflistcount += 1
        autocmd BufDelete * let g:zbuflistcount -= 1
        autocmd VimEnter * call UpdateZBufLC()
        function UpdateZBufLC()
                let lst = range(1, bufnr('$'))
                call filter(lst, 'buflisted(v:val)')
                let g:zbuflistcount = len(lst)
        endfunction

In addition to the above code, I had to add "nested" to several autocmds
that were preventing the "BufAdd" from firing.

I've been running with this scheme for a bit and it seems pretty stable.

Thanks a lot for everyone's help.

--Matt

Reply via email to