]> granicus.if.org Git - vim/commitdiff
patch 8.2.4609: :unhide does not check for failing to close a window v8.2.4609
authorBram Moolenaar <Bram@vim.org>
Tue, 22 Mar 2022 18:13:01 +0000 (18:13 +0000)
committerBram Moolenaar <Bram@vim.org>
Tue, 22 Mar 2022 18:13:01 +0000 (18:13 +0000)
Problem:    :unhide does not check for failing to close a window.
Solution:   When closing a window fails continue with the next one.  Do not
            try closing the autocmd window. (closes #9984)

src/buffer.c
src/proto/window.pro
src/testdir/test_autocmd.vim
src/version.c
src/window.c

index 8e68d94248245fea3fe87971d3889bff6ee80987..2dac4874c57def7ea42b368707f84d8ef03a3b96 100644 (file)
@@ -5330,17 +5330,21 @@ ex_buffer_all(exarg_T *eap)
        {
            wpnext = wp->w_next;
            if ((wp->w_buffer->b_nwindows > 1
-                   || ((cmdmod.cmod_split & WSP_VERT)
-                       ? wp->w_height + wp->w_status_height < Rows - p_ch
-                                                           - tabline_height()
-                       : wp->w_width != Columns)
-                   || (had_tab > 0 && wp != firstwin)) && !ONE_WINDOW
-                            && !(wp->w_closing || wp->w_buffer->b_locked > 0))
+                       || ((cmdmod.cmod_split & WSP_VERT)
+                           ? wp->w_height + wp->w_status_height < Rows - p_ch
+                                                            - tabline_height()
+                           : wp->w_width != Columns)
+                       || (had_tab > 0 && wp != firstwin))
+                   && !ONE_WINDOW
+                   && !(wp->w_closing || wp->w_buffer->b_locked > 0)
+                   && !win_unlisted(wp))
            {
-               win_close(wp, FALSE);
-               wpnext = firstwin;      // just in case an autocommand does
-                                       // something strange with windows
-               tpnext = first_tabpage; // start all over...
+               if (win_close(wp, FALSE) == FAIL)
+                   break;
+               // Just in case an autocommand does something strange with
+               // windows: start all over...
+               wpnext = firstwin;
+               tpnext = first_tabpage;
                open_wins = 0;
            }
            else
index 11c2d47c70bf33966f54398ef8280f1a021adb33..1954dfd0ba9f910dc6fa50b64ec94513fa0f14e4 100644 (file)
@@ -46,6 +46,7 @@ win_T *win_horz_neighbor(tabpage_T *tp, win_T *wp, int left, long count);
 void win_enter(win_T *wp, int undo_sync);
 win_T *buf_jump_open_win(buf_T *buf);
 win_T *buf_jump_open_tab(buf_T *buf);
+int win_unlisted(win_T *wp);
 void win_free_popup(win_T *win);
 void win_remove(win_T *wp, tabpage_T *tp);
 int win_alloc_lines(win_T *wp);
index 7be0c1815acaadff46fa5700ebe046a2bdd0666e..688508a856da55757a0a030fa7b513c132295715 100644 (file)
@@ -3,6 +3,7 @@
 source shared.vim
 source check.vim
 source term_util.vim
+import './vim9.vim' as v9
 
 func s:cleanup_buffers() abort
   for bnr in range(1, bufnr('$'))
@@ -2975,4 +2976,18 @@ func Test_Changed_ChangedI()
   bw!
 endfunc
 
+func Test_closing_autocmd_window()
+  let lines =<< trim END
+      edit Xa.txt
+      tabnew Xb.txt
+      autocmd BufEnter Xa.txt unhide 1
+      doautoall BufEnter
+  END
+  call v9.CheckScriptFailure(lines, 'E814:')
+  au! BufEnter
+  only!
+  bwipe Xa.txt
+  bwipe Xb.txt
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 2180ebf264c919b9d37201f9b44a696b66be263c..cd3d9cdeed4f53a496d0d906cdb04409c820c6be 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4609,
 /**/
     4608,
 /**/
index cf11acf8933a94459151040d149e216de65b621f..435ad037ac171f3ebbb5eb014b5fd1f20a0050f2 100644 (file)
@@ -43,7 +43,6 @@ static int frame_minheight(frame_T *topfrp, win_T *next_curwin);
 static int may_open_tabpage(void);
 static int win_enter_ext(win_T *wp, int flags);
 static void win_free(win_T *wp, tabpage_T *tp);
-static int win_unlisted(win_T *wp);
 static void win_append(win_T *after, win_T *wp);
 static void frame_append(frame_T *after, frame_T *frp);
 static void frame_insert(frame_T *before, frame_T *frp);
@@ -5233,7 +5232,7 @@ win_free(
  * Return TRUE if "wp" is not in the list of windows: the autocmd window or a
  * popup window.
  */
-    static int
+    int
 win_unlisted(win_T *wp)
 {
     return wp == aucmd_win || WIN_IS_POPUP(wp);