0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

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)
This commit is contained in:
Bram Moolenaar
2022-11-19 13:14:10 +00:00
parent 361895d2a1
commit 9fda81515b
5 changed files with 23 additions and 11 deletions

View File

@@ -6055,7 +6055,7 @@ ex_win_close(
emsg(_(e_cannot_close_autocmd_or_popup_window)); emsg(_(e_cannot_close_autocmd_or_popup_window));
return; return;
} }
if (window_layout_locked()) if (window_layout_locked(CMD_close))
return; return;
need_hide = (bufIsChanged(buf) && buf->b_nwindows <= 1); need_hide = (bufIsChanged(buf) && buf->b_nwindows <= 1);
@@ -6229,7 +6229,7 @@ ex_tabclose(exarg_T *eap)
cmdwin_result = K_IGNORE; cmdwin_result = K_IGNORE;
else if (first_tabpage->tp_next == NULL) else if (first_tabpage->tp_next == NULL)
emsg(_(e_cannot_close_last_tab_page)); emsg(_(e_cannot_close_last_tab_page));
else if (!window_layout_locked()) else if (!window_layout_locked(CMD_tabclose))
{ {
tab_number = get_tabpage_arg(eap); tab_number = get_tabpage_arg(eap);
if (eap->errmsg == NULL) if (eap->errmsg == NULL)
@@ -6265,7 +6265,7 @@ ex_tabonly(exarg_T *eap)
cmdwin_result = K_IGNORE; cmdwin_result = K_IGNORE;
else if (first_tabpage->tp_next == NULL) else if (first_tabpage->tp_next == NULL)
msg(_("Already only one tab page")); msg(_("Already only one tab page"));
else if (!window_layout_locked()) else if (!window_layout_locked(CMD_tabonly))
{ {
tab_number = get_tabpage_arg(eap); tab_number = get_tabpage_arg(eap);
if (eap->errmsg == NULL) if (eap->errmsg == NULL)
@@ -6298,7 +6298,7 @@ ex_tabonly(exarg_T *eap)
void void
tabpage_close(int forceit) tabpage_close(int forceit)
{ {
if (window_layout_locked()) if (window_layout_locked(CMD_tabclose))
return; return;
// First close all the windows but the current one. If that worked then // 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)
static void static void
ex_only(exarg_T *eap) ex_only(exarg_T *eap)
{ {
if (window_layout_locked()) if (window_layout_locked(CMD_only))
return; return;
# ifdef FEAT_GUI # ifdef FEAT_GUI
need_mouse_correct = TRUE; need_mouse_correct = TRUE;
@@ -6373,7 +6373,7 @@ ex_hide(exarg_T *eap UNUSED)
// ":hide" or ":hide | cmd": hide current window // ":hide" or ":hide | cmd": hide current window
if (!eap->skip) if (!eap->skip)
{ {
if (window_layout_locked()) if (window_layout_locked(CMD_hide))
return; return;
#ifdef FEAT_GUI #ifdef FEAT_GUI
need_mouse_correct = TRUE; need_mouse_correct = TRUE;

View File

@@ -1,5 +1,5 @@
/* window.c */ /* window.c */
int window_layout_locked(void); int window_layout_locked(enum CMD_index cmd);
win_T *prevwin_curwin(void); win_T *prevwin_curwin(void);
void do_window(int nchar, long Prenum, int xchar); void do_window(int nchar, long Prenum, int xchar);
void get_wincmd_addr_type(char_u *arg, exarg_T *eap); void get_wincmd_addr_type(char_u *arg, exarg_T *eap);

View File

@@ -756,6 +756,14 @@ func Test_BufEnter()
bwipe! bwipe!
au! BufEnter au! BufEnter
endfor endfor
new
new
autocmd BufEnter * ++once close
call assert_fails('close', 'E1312:')
au! BufEnter
only
endfunc endfunc
" Closing a window might cause an endless loop " Closing a window might cause an endless loop

View File

@@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
909,
/**/ /**/
908, 908,
/**/ /**/

View File

@@ -111,13 +111,15 @@ window_layout_unlock(void)
/* /*
* When the window layout cannot be changed give an error and return TRUE. * When the window layout cannot be changed give an error and return TRUE.
* "cmd" indicates the action being performed and is used to pick the relevant
* error message.
*/ */
int int
window_layout_locked(void) window_layout_locked(enum CMD_index cmd)
{ {
if (split_disallowed > 0 || close_disallowed > 0) if (split_disallowed > 0 || close_disallowed > 0)
{ {
if (close_disallowed == 0) if (close_disallowed == 0 && cmd == CMD_tabnew)
emsg(_(e_cannot_split_window_when_closing_buffer)); emsg(_(e_cannot_split_window_when_closing_buffer));
else else
emsg(_(e_not_allowed_to_change_window_layout_in_this_autocmd)); emsg(_(e_not_allowed_to_change_window_layout_in_this_autocmd));
@@ -2573,7 +2575,7 @@ win_close(win_T *win, int free_buf)
emsg(_(e_cannot_close_last_window)); emsg(_(e_cannot_close_last_window));
return FAIL; return FAIL;
} }
if (window_layout_locked()) if (window_layout_locked(CMD_close))
return FAIL; return FAIL;
if (win->w_closing || (win->w_buffer != NULL if (win->w_closing || (win->w_buffer != NULL
@@ -4062,7 +4064,7 @@ win_new_tabpage(int after)
emsg(_(e_invalid_in_cmdline_window)); emsg(_(e_invalid_in_cmdline_window));
return FAIL; return FAIL;
} }
if (window_layout_locked()) if (window_layout_locked(CMD_tabnew))
return FAIL; return FAIL;
newtp = alloc_tabpage(); newtp = alloc_tabpage();