On 25-Feb-09 12:31, Ingo Karkat wrote:
> Hello VIM Developers,
> 
> According to the help, v:warningmsg contains the last given warning message. 
> I've encountered multiple VIM warnings which do not update this variable:
> 
> vim -N -u NONE
> :setl ro
> :normal! oFoobar
> W10: Warning: Changing a readonly file-- INSERT --
> :echo v:warningmsg
> 
> " I would have expected that v:warningmsg now contains W10: ...
> /Foo
> search hit BOTTOM, continuing at TOP
> :echo v:warningmsg
> search hit BOTTOM, continuing at TOP
> " OK here, the wrapscan message sets v:warningmsg as expected.
> :w foo
> W10: Warning: Changing a readonly file
> :echo v:warningmsg
> search hit BOTTOM, continuing at TOP
> " v:warningmsg not set, still contains the old warning.
> :normal! oMore text
> :!echo "Changed" >> foo
> [No write since last change]
> W12: Warning: File "foo" has changed and the buffer was changed in Vim as well
> See ":help W12" for more info.
> [O]K, (L)oad File:
> :echo v:warningmsg
> search hit BOTTOM, continuing at TOP
> " It's not just W10, W12 also doesn't set v:warningmsg.
> 
> I can reproduce this with VIM 7.2.127 on Linux and the default VIM 7.0 - 7.2 
> on 
> Windows.

Addendum: Here's why this bug is important (to me):

I was writing a custom command that modifies the current buffer, and wanted to 
avoid the horrible multi-line prompt:
     Error detected while processing function ...
     W10: Warning: Changing a readonly file
and just print the warning / error, like the built-in commands do. So I tried 
this:
     function! s:MyCmd()
        let v:warningmsg = ''
        " ... Omitting commands which modify the current buffer,
        " and using :silent! {cmd}.
        if ! empty(v:warningmsg)
            echohl WarningMsg|echomsg v:warningmsg|echohl None
        endif
     endfunction
     command MyCmd call <SID>MyCmd

Because of this bug, I ended up making a "neutral" modification before calling 
the function, so that the warning is triggered outside of a function (and thus 
does not print "Error detected while processing function ...":

     command MyCmd call setline(1,getline(1))|call <SID>MyCmd

Does anyone know a better way to implement this (without explicitly checking 
&ro 
and &modifiable, which would just duplicate core VIM functionality)?

-- regards, ingo

-- 
   -- Ingo Karkat -- /^-- /^-- /^-- /^-- /^-- /^-- http://ingo-karkat.de/ --


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui