summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-06-26 19:44:06 +0200
committerBram Moolenaar <Bram@vim.org>2020-06-26 19:44:06 +0200
commitcf8441704d6e517bda1899f4afa82c6b4eecbaec (patch)
tree426b55ece4b23b41dfdbade5c64aeaafe3db8693
parentfc838d6cb0f22c77a6ee2befd034b593e1c5ea06 (diff)
patch 8.2.1059: crash when using :tabonly in an autocommandv8.2.1059
Problem: Crash when using :tabonly in an autocommand. (Yegappan Lakshmanan) Solution: Do not allow the autocommand window to be closed.
-rw-r--r--src/ex_docmd.c7
-rw-r--r--src/globals.h1
-rw-r--r--src/testdir/test_autocmd.vim22
-rw-r--r--src/version.c2
-rw-r--r--src/window.c2
5 files changed, 32 insertions, 2 deletions
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 6c887fae1c..2469df341c 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -5178,6 +5178,13 @@ ex_win_close(
int need_hide;
buf_T *buf = win->w_buffer;
+ // Never close the autocommand window.
+ if (win == aucmd_win)
+ {
+ emsg(_(e_autocmd_close));
+ return;
+ }
+
need_hide = (bufIsChanged(buf) && buf->b_nwindows <= 1);
if (need_hide && !buf_hide(buf) && !forceit)
{
diff --git a/src/globals.h b/src/globals.h
index c7f9794ab9..03a6937561 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -1765,6 +1765,7 @@ EXTERN char e_float_as_string[] INIT(= N_("E806: using Float as a String"));
#endif
EXTERN char e_dirnotf[] INIT(= N_("E919: Directory not found in '%s': \"%s\""));
EXTERN char e_au_recursive[] INIT(= N_("E952: Autocommand caused recursive behavior"));
+EXTERN char e_autocmd_close[] INIT(= N_("E813: Cannot close autocmd or popup window"));
#ifdef FEAT_MENU
EXTERN char e_menuothermode[] INIT(= N_("E328: Menu only exists in another mode"));
#endif
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index d7328c3e0a..446d22bd71 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -2617,7 +2617,27 @@ func Test_close_autocmd_window()
au!
augroup END
augroup! aucmd_win_test2
- %bw!
+ %bwipe!
+endfunc
+
+" Test for trying to close the tab that has the temporary window for exeucing
+" an autocmd.
+func Test_close_autocmd_tab()
+ edit one.txt
+ tabnew two.txt
+ augroup aucmd_win_test
+ au!
+ au BufEnter * if expand('<afile>') == 'one.txt' | tabfirst | tabonly | endif
+ augroup END
+
+ call assert_fails('doautoall BufEnter', 'E813:')
+
+ tabonly
+ augroup aucmd_win_test
+ au!
+ augroup END
+ augroup! aucmd_win_test
+ %bwipe!
endfunc
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index de8807a528..aff4583e94 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1059,
+/**/
1058,
/**/
1057,
diff --git a/src/window.c b/src/window.c
index 095eabed2b..e2adc0cb9f 100644
--- a/src/window.c
+++ b/src/window.c
@@ -2461,7 +2461,7 @@ win_close(win_T *win, int free_buf)
return FAIL; // window is already being closed
if (win_unlisted(win))
{
- emsg(_("E813: Cannot close autocmd or popup window"));
+ emsg(_(e_autocmd_close));
return FAIL;
}
if ((firstwin == aucmd_win || lastwin == aucmd_win) && one_window())