I am enhancing my cyclecolor script and would like to use another
buffer, but would like to do it as transparently as possible.

I use bufnr(filename, 1) to create a new buffer, then save the current
buffer number, switch to the new buffer, do some things, and switch
back.  Later in the script, I use echo to display a message.  When I
return from the script, the message has been overwritten by the output
of  exec "b" curbuf  which was used to restore the original buffer, even
though the :echo was after the :b command.

Can someone point me to a help topic that explains this (or give an
explanation)?  Is there some way to keep the output of echo (without
changing the user's commandheight)?  I've tried  exec "silent! b"
curbuf, and using echomsg instead of echo, but no combination of those
worked.

As an example, edit some file, then create a new buffer (I used
call bufnr('testbuf.vim', 1) ) and paste the following into it:

function! TestBuf()
        let curbuf = bufnr("%")
        exec "b" g:testbuf
        let found = search('t.st')
        exec "b" curbuf

        echomsg 'Done with TestBuf (found = '.found.')'
endfunction

Then do the following:

:w
:let g:testbuf = 2 " assuming this is buffer 2
:so %
:b #
:call TestBuf()

At this point, I see the output from  exec "b" curbuf  but using
:messages I can see that the echomsg did indeed display (before the
output from :b).  I also tried redraw between the :b and the :echomsg.

Thanks much...Marvin

Reply via email to