Bram: 'exe "silent <command>"' apparently does not give the same result as ':silent exe <command>' (see example below). Bug or feature?

Marvin Renich wrote:
* A.J.Mechelynck <[EMAIL PROTECTED]> [060723 20:48]:
Marvin Renich wrote:
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.

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

Thanks much...Marvin
see ":help :silent"


HTH,
Tony.

I tried silent and silent!.  I used it both places where I change
buffers with

    exec "b" ...

e.g. exec "silent! b" ...

Did I miss something or put it in the wrong place?

Note that if you do the steps in my original message, then look at the
output of :messages, you will see that the output of the first exec "b"
... does not appear, and the output of the second appears _after_ the
output of echomsg, rather than before.  Changing exec "b" to exec
"silent! b" has no effect.

I am using a self-compiled vim 7.0 that is slightly out-of-date (it only
has patches through 17).  If you can't reproduce my problem with the
steps I outlined in my original message, I'll update my source,
recompile, and retry.

:version
VIM - Vi IMproved 7.0 (2006 May 7, compiled May 31 2006 17:11:36)
Included patches: 1-17

Thanks...Marvin

P.S.  I am subscribed; no need to CC me.




No need, but it's easier: "Reply to All" does it. ("Reply to Sender" would write only to you, not to the list; to write only to the list I have to remove the Cc: line by hand.)

        gvim -N -u NONE
        :version

VIM - Vi IMproved 7.0 (2006 May 7, compiled Jul 23 2006 22:50:51)
Included patches: 1-42
Compiled by [EMAIL PROTECTED]
Huge version with GTK2-GNOME GUI.  Features included (+) or not (-):
[...]

        " read the function
        :source testbuf.vim

        :let g:testbuf = foobar
        call TestBuf()

Error detected while processing function TestBuf:
line    2:
E94: No matching buffer for foobar
Done with TestBuf (found = 0)

        :e foobar
        :new
        :call TestBuf()

Done with TestBuf (found = 0)
"[No Name]" --No lines in buffer--

        " only the latter message is seen in this case


Let's change the "echomsg" command to "return" with the same string as argument, write, source %, and see what happens...

        :echo TestBuf()

"testbuf.vim"
"testbuf.vim" 7L, 170C
Done with TestBuf (found = 0)

        " this time two lines are displayed (the last two above),
        " with a Hit-Enter-ptompt

...replace 'exec "b"' by 'silent exec "b"' (twice), write, source %

        :echo TestBuf()

"testbuf.vim"
"testbuf.vim" 7L, 170C
Done with TestBuf (found = 0)

        " this time only the last message is shown (but since I'm
        " pasting the output by ":redir" to the clipboard, some
        " undisplayed messages are shown above).

Conclusion: It's ":silent exe blahblah", not ":exe 'silent' blahblah". Note that about half a screen below ":help :silent" there is an example with ":silent exe normal".


Note: While doing those tests, I found that if the current buffer is modified, the function will give an error at line 2. You may want to add

        let save_hidden = &hidden
        set hidden

at the start of the function, and

        let &hidden = save_hidden

before returning. OTOH I don't quite understand why you must search an auxiliary buffer rather than the current one being edited.


Best regards,
Tony.

Reply via email to