patch 8.2.4609: :unhide does not check for failing to close a window

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)
diff --git a/src/buffer.c b/src/buffer.c
index 8e68d94..2dac487 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -5330,17 +5330,21 @@
 	{
 	    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
diff --git a/src/proto/window.pro b/src/proto/window.pro
index 11c2d47..1954dfd 100644
--- a/src/proto/window.pro
+++ b/src/proto/window.pro
@@ -46,6 +46,7 @@
 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);
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 7be0c18..688508a 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
Binary files differ
diff --git a/src/version.c b/src/version.c
index 2180ebf..cd3d9cd 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4609,
+/**/
     4608,
 /**/
     4607,
diff --git a/src/window.c b/src/window.c
index cf11acf..435ad03 100644
--- a/src/window.c
+++ b/src/window.c
@@ -43,7 +43,6 @@
 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 @@
  * 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);