redraw_custom_statusline(win_T *wp)
{
static int entered = FALSE;
- int save_called_emsg = called_emsg;
+ int saved_did_emsg = did_emsg;
/* When called recursively return. This can happen when the statusline
* contains an expression that triggers a redraw. */
return;
entered = TRUE;
- called_emsg = FALSE;
+ did_emsg = FALSE;
win_redr_custom(wp, FALSE);
- if (called_emsg)
+ if (did_emsg)
{
/* When there is an error disable the statusline, otherwise the
* display is messed up with errors and a redraw triggers the problem
(char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL
? OPT_LOCAL : OPT_GLOBAL), SID_ERROR);
}
- called_emsg |= save_called_emsg;
+ did_emsg |= saved_did_emsg;
entered = FALSE;
}
#endif
--- /dev/null
+function! StatuslineWithCaughtError()
+ let s:func_in_statusline_called = 1
+ try
+ call eval('unknown expression')
+ catch
+ endtry
+ return ''
+endfunction
+
+function! StatuslineWithError()
+ let s:func_in_statusline_called = 1
+ call eval('unknown expression')
+ return ''
+endfunction
+
+function! Test_caught_error_in_statusline()
+ let s:func_in_statusline_called = 0
+ set laststatus=2
+ let statusline = '%{StatuslineWithCaughtError()}'
+ let &statusline = statusline
+ redrawstatus
+ call assert_true(s:func_in_statusline_called)
+ call assert_equal(statusline, &statusline)
+ set statusline=
+endfunction
+
+function! Test_statusline_will_be_disabled_with_error()
+ let s:func_in_statusline_called = 0
+ set laststatus=2
+ let statusline = '%{StatuslineWithError()}'
+ try
+ let &statusline = statusline
+ redrawstatus
+ catch
+ endtry
+ call assert_true(s:func_in_statusline_called)
+ call assert_equal('', &statusline)
+ set statusline=
+endfunction