Subject: bug#12764: 24.2; `quit-window' wrongly iconifies frame

From: martin rudalics <[email-masked]>
Date: Tue, 30 Oct 2012 11:27:40 +0100

>> There's a regression in Emacs 24 compared to Emacs 23 wrt the behavior
 >> of `quit-window'. In some circumstances, it iconifies frames that were
 >> existing before the current buffer was created, which (AIUI) it's not
 >> supposed to do.
 >>
 >> Recipe starting from `emacs -Q':
 >> - C-x 5 2 to create a new frame
 >> - in the new frame, M-x man RET emacs RET
 >> - C-x 0 to make the man buffer the current buffer

Which means that we now have a single-window frame where that window has
been specially created for showing man.  We could intepret the user's
intentions here also as "show me man in a separate, dedicated frame".

 >> - q
 >>
 >> When you hit `q' the frame gets iconified, even though it was not
 >> created by M-x man.
 >
 > I think the attached patch is required to fix this.  Martin, please
 > review, thanks.

I'm not sure whether the current behavior should be considered incorrect
or a feature.  C-x 5 2 usually shows the same buffer as in the previous
frame's selected window.  Showing it instead of man doesn't strike me as
something very useful.

OTOH if the user has worked on a different buffer in the new frame and
used C-x 0 in order to temporarily show more of the man page, it makes
sense to show that other buffer again.  And if users really wanted to
show man on a separate frame, they could do so immediately.

In any case I'd propose the slightly different patch below.
	
martin

*** lisp/window.el	2012-10-27 08:58:30 +0000
--- lisp/window.el	2012-10-30 09:51:16 +0000
***************
*** 3556,3562 ****
   	 quad entry)
       (cond
        ((and (not prev-buffer)
! 	   (memq (nth 1 quit-restore) '(window frame))
   	   (eq (nth 3 quit-restore) buffer)
   	   ;; Delete WINDOW if possible.
   	   (window--delete window nil (eq bury-or-kill 'kill)))
--- 3556,3567 ----
   	 quad entry)
       (cond
        ((and (not prev-buffer)
! 	   (or (eq (nth 1 quit-restore) 'frame)
! 	       (and (eq (nth 1 quit-restore) 'window)
! 		    ;; If the window has been created on an existing
! 		    ;; frame and winds up as the sole window on that
! 		    ;; frame, do not delete it (Bug#12764).
! 		    (not (eq window (frame-root-window window)))))
   	   (eq (nth 3 quit-restore) buffer)
   	   ;; Delete WINDOW if possible.
   	   (window--delete window nil (eq bury-or-kill 'kill)))