Skip to content

Commit 9fda815

Browse files
committed
patch 9.0.0909: error message for layout change does not match action
Problem: Error message for layout change does not match action. Solution: Pass the command to where the error is given. (closes #11573)
1 parent 361895d commit 9fda815

5 files changed

Lines changed: 23 additions & 11 deletions

File tree

src/ex_docmd.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6055,7 +6055,7 @@ ex_win_close(
60556055
emsg(_(e_cannot_close_autocmd_or_popup_window));
60566056
return;
60576057
}
6058-
if (window_layout_locked())
6058+
if (window_layout_locked(CMD_close))
60596059
return;
60606060

60616061
need_hide = (bufIsChanged(buf) && buf->b_nwindows <= 1);
@@ -6229,7 +6229,7 @@ ex_tabclose(exarg_T *eap)
62296229
cmdwin_result = K_IGNORE;
62306230
else if (first_tabpage->tp_next == NULL)
62316231
emsg(_(e_cannot_close_last_tab_page));
6232-
else if (!window_layout_locked())
6232+
else if (!window_layout_locked(CMD_tabclose))
62336233
{
62346234
tab_number = get_tabpage_arg(eap);
62356235
if (eap->errmsg == NULL)
@@ -6265,7 +6265,7 @@ ex_tabonly(exarg_T *eap)
62656265
cmdwin_result = K_IGNORE;
62666266
else if (first_tabpage->tp_next == NULL)
62676267
msg(_("Already only one tab page"));
6268-
else if (!window_layout_locked())
6268+
else if (!window_layout_locked(CMD_tabonly))
62696269
{
62706270
tab_number = get_tabpage_arg(eap);
62716271
if (eap->errmsg == NULL)
@@ -6298,7 +6298,7 @@ ex_tabonly(exarg_T *eap)
62986298
void
62996299
tabpage_close(int forceit)
63006300
{
6301-
if (window_layout_locked())
6301+
if (window_layout_locked(CMD_tabclose))
63026302
return;
63036303

63046304
// First close all the windows but the current one. If that worked then
@@ -6346,7 +6346,7 @@ tabpage_close_other(tabpage_T *tp, int forceit)
63466346
static void
63476347
ex_only(exarg_T *eap)
63486348
{
6349-
if (window_layout_locked())
6349+
if (window_layout_locked(CMD_only))
63506350
return;
63516351
# ifdef FEAT_GUI
63526352
need_mouse_correct = TRUE;
@@ -6373,7 +6373,7 @@ ex_hide(exarg_T *eap UNUSED)
63736373
// ":hide" or ":hide | cmd": hide current window
63746374
if (!eap->skip)
63756375
{
6376-
if (window_layout_locked())
6376+
if (window_layout_locked(CMD_hide))
63776377
return;
63786378
#ifdef FEAT_GUI
63796379
need_mouse_correct = TRUE;

src/proto/window.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* window.c */
2-
int window_layout_locked(void);
2+
int window_layout_locked(enum CMD_index cmd);
33
win_T *prevwin_curwin(void);
44
void do_window(int nchar, long Prenum, int xchar);
55
void get_wincmd_addr_type(char_u *arg, exarg_T *eap);

src/testdir/test_autocmd.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,14 @@ func Test_BufEnter()
756756
bwipe!
757757
au! BufEnter
758758
endfor
759+
760+
new
761+
new
762+
autocmd BufEnter * ++once close
763+
call assert_fails('close', 'E1312:')
764+
765+
au! BufEnter
766+
only
759767
endfunc
760768

761769
" Closing a window might cause an endless loop

src/version.c

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

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
909,
698700
/**/
699701
908,
700702
/**/

src/window.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,15 @@ window_layout_unlock(void)
111111

112112
/*
113113
* When the window layout cannot be changed give an error and return TRUE.
114+
* "cmd" indicates the action being performed and is used to pick the relevant
115+
* error message.
114116
*/
115117
int
116-
window_layout_locked(void)
118+
window_layout_locked(enum CMD_index cmd)
117119
{
118120
if (split_disallowed > 0 || close_disallowed > 0)
119121
{
120-
if (close_disallowed == 0)
122+
if (close_disallowed == 0 && cmd == CMD_tabnew)
121123
emsg(_(e_cannot_split_window_when_closing_buffer));
122124
else
123125
emsg(_(e_not_allowed_to_change_window_layout_in_this_autocmd));
@@ -2573,7 +2575,7 @@ win_close(win_T *win, int free_buf)
25732575
emsg(_(e_cannot_close_last_window));
25742576
return FAIL;
25752577
}
2576-
if (window_layout_locked())
2578+
if (window_layout_locked(CMD_close))
25772579
return FAIL;
25782580

25792581
if (win->w_closing || (win->w_buffer != NULL
@@ -4062,7 +4064,7 @@ win_new_tabpage(int after)
40624064
emsg(_(e_invalid_in_cmdline_window));
40634065
return FAIL;
40644066
}
4065-
if (window_layout_locked())
4067+
if (window_layout_locked(CMD_tabnew))
40664068
return FAIL;
40674069

40684070
newtp = alloc_tabpage();

0 commit comments

Comments
 (0)