Skip to content

Commit a742e08

Browse files
committed
patch 7.4.1711
Problem: When using try/catch in 'statusline' it is still considered an error and the status line will be disabled. Solution: Check did_emsg instead of called_emsg. (haya14busa, closes #729)
1 parent 17fe5e1 commit a742e08

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

src/screen.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6779,17 +6779,17 @@ win_redr_status(win_T *wp)
67796779
redraw_custom_statusline(win_T *wp)
67806780
{
67816781
static int entered = FALSE;
6782-
int save_called_emsg = called_emsg;
6782+
int saved_did_emsg = did_emsg;
67836783

67846784
/* When called recursively return. This can happen when the statusline
67856785
* contains an expression that triggers a redraw. */
67866786
if (entered)
67876787
return;
67886788
entered = TRUE;
67896789

6790-
called_emsg = FALSE;
6790+
did_emsg = FALSE;
67916791
win_redr_custom(wp, FALSE);
6792-
if (called_emsg)
6792+
if (did_emsg)
67936793
{
67946794
/* When there is an error disable the statusline, otherwise the
67956795
* display is messed up with errors and a redraw triggers the problem
@@ -6798,7 +6798,7 @@ redraw_custom_statusline(win_T *wp)
67986798
(char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL
67996799
? OPT_LOCAL : OPT_GLOBAL), SID_ERROR);
68006800
}
6801-
called_emsg |= save_called_emsg;
6801+
did_emsg |= saved_did_emsg;
68026802
entered = FALSE;
68036803
}
68046804
#endif

src/testdir/test_alot.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ source test_reltime.vim
2222
source test_searchpos.vim
2323
source test_set.vim
2424
source test_sort.vim
25+
source test_statusline.vim
2526
source test_syn_attr.vim
2627
source test_timers.vim
2728
source test_undolevels.vim

src/testdir/test_statusline.vim

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function! StatuslineWithCaughtError()
2+
let s:func_in_statusline_called = 1
3+
try
4+
call eval('unknown expression')
5+
catch
6+
endtry
7+
return ''
8+
endfunction
9+
10+
function! StatuslineWithError()
11+
let s:func_in_statusline_called = 1
12+
call eval('unknown expression')
13+
return ''
14+
endfunction
15+
16+
function! Test_caught_error_in_statusline()
17+
let s:func_in_statusline_called = 0
18+
set laststatus=2
19+
let statusline = '%{StatuslineWithCaughtError()}'
20+
let &statusline = statusline
21+
redrawstatus
22+
call assert_true(s:func_in_statusline_called)
23+
call assert_equal(statusline, &statusline)
24+
set statusline=
25+
endfunction
26+
27+
function! Test_statusline_will_be_disabled_with_error()
28+
let s:func_in_statusline_called = 0
29+
set laststatus=2
30+
let statusline = '%{StatuslineWithError()}'
31+
try
32+
let &statusline = statusline
33+
redrawstatus
34+
catch
35+
endtry
36+
call assert_true(s:func_in_statusline_called)
37+
call assert_equal('', &statusline)
38+
set statusline=
39+
endfunction

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,8 @@ static char *(features[]) =
748748

749749
static int included_patches[] =
750750
{ /* Add new patch number below this line */
751+
/**/
752+
1711,
751753
/**/
752754
1710,
753755
/**/

0 commit comments

Comments
 (0)