On 26-Feb-09 4:21, Bram Moolenaar wrote:
> Ingo Karkat wrote:
>> 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.
>
> I'll add it to the todo list. Note that you need to mention every
> message you are missing, there probably is no generic solution.
Actually, the only (!) message that sets v:warningmsg is the "search hit
BOTTOM,
continuing at TOP" (and its reverse) warning.
While grepping through the source code, I found out that there are different
kinds of warning: With or without highlighting, with /W\d\+:/ prefix and/or
prefixed with "Warning:", echoed to the command line or (in some (correct)
cases) to stderr. Many purported warnings are actually echoed as errors, BTW.
Thus, I actually found surprisingly few warnings that should be stored in
v:warningmsg.
Attached patch adds the setting of v:warningmsg for:
- W10: Warning: Changing a readonly file
- The W11, W12, W13, W16 "file has changed" warnings
- W17: Arabic requires UTF-8, do ':set encoding=utf-8' (just for completeness'
sake, not sure why someone would be interested in this)
Please review the patch, my C is a bit rusty, and I'm not well versed in the
string types and message translation macros used in the sources.
-- 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
-~----------~----~----~----~------~----~------~--~---
Index: src/misc1.c
===================================================================
--- src/misc1.c (revision 1390)
+++ src/misc1.c (working copy)
@@ -2955,6 +2955,7 @@
int col; /* column for message; non-zero when in
insert
mode and 'showmode' is on */
{
+ char_u *readonly_msg = _("W10: Warning: Changing a readonly file");
if (curbuf->b_did_warn == FALSE
&& curbufIsChanged() == 0
#ifdef FEAT_AUTOCMD
@@ -2977,8 +2978,10 @@
if (msg_row == Rows - 1)
msg_col = col;
msg_source(hl_attr(HLF_W));
- MSG_PUTS_ATTR(_("W10: Warning: Changing a readonly file"),
- hl_attr(HLF_W) | MSG_HIST);
+ MSG_PUTS_ATTR(readonly_msg, hl_attr(HLF_W) | MSG_HIST);
+#ifdef FEAT_EVAL
+ set_vim_var_string(VV_WARNINGMSG, readonly_msg, -1);
+#endif
msg_clr_eos();
(void)msg_end();
if (msg_silent == 0 && !silent_mode)
Index: src/fileio.c
===================================================================
--- src/fileio.c (revision 1390)
+++ src/fileio.c (working copy)
@@ -6598,6 +6598,12 @@
tbuf = alloc((unsigned)(STRLEN(path) + STRLEN(mesg)
+ STRLEN(mesg2) + 2));
sprintf((char *)tbuf, mesg, path);
+#ifdef FEAT_EVAL
+ /* Set warningmsg here, before the unimportant and output-specific
+ * mesg2 has been appended.
+ */
+ set_vim_var_string(VV_WARNINGMSG, tbuf, -1);
+#endif
#if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG)
if (can_reload)
{
Index: src/option.c
===================================================================
--- src/option.c (revision 1390)
+++ src/option.c (working copy)
@@ -7541,9 +7541,12 @@
* set. */
if (STRCMP(p_enc, "utf-8") != 0)
{
+ char_u* arabic_encoding_msg = _("W17: Arabic requires UTF-8, do
':set encoding=utf-8'");
msg_source(hl_attr(HLF_W));
- MSG_ATTR(_("W17: Arabic requires UTF-8, do ':set
encoding=utf-8'"),
- hl_attr(HLF_W));
+ MSG_ATTR(arabic_encoding_msg, hl_attr(HLF_W));
+#ifdef FEAT_EVAL
+ set_vim_var_string(VV_WARNINGMSG, arabic_encoding_msg, -1);
+#endif
}
# ifdef FEAT_MBYTE