Reputation: 2521
I am trying to maintain an error message chain by passing start-up time errors to vim's error control system. For that I have the following function in my .vimrc:
" Local error message function
function! LocalError(err)
" Update the errorMessageString
let g:errorMessageString = a:err
autocmd VimEnter * echohl ErrorMsg | echomsg g:errorMessageString | echohl None
endfunction
So this function is accessible down the stream, by any other scripts that are being sourced. So each one of those calls this function with a slightly different message string.
However once I display those in vim with the :messages command I able to see the multiple lines of message strings but all of them are identical.
As if the message buffer is always being overwritten by the last string that has been provided to the function. What I am doing wrong?
Here is what it should look like:
<banana> (SEVERE_ERROR): Unable to access.
<foo> (SEVERE_ERROR): Unable to access.
However it looks like this:
<foo> (SEVERE_ERROR): Unable to access.
<foo> (SEVERE_ERROR): Unable to access.
Any ideas?
Thanks.
Upvotes: 1
Views: 643
Reputation: 172748
The problem is that the global g:errorMessageString
variable is overwritten on each function invocation, but the defined :autocmd
s will execute only later, using the then current value of the global variable.
One way to fix this is to evaluate the variable's contents into the :autocmd
via :execute
:
execute 'autocmd VimEnter * echohl ErrorMsg | echomsg' string(g:errorMessageString) '| echohl None'
Or you could define g:errorMessageString
as a List, append the function argument on each invocation, and define the :autocmd
only once, but then have it :echomsg
over all List elements.
Upvotes: 3