Subject: Re: bug#1259: quit-window: does it quit the wrong buffer?

From: martin rudalics <[email-masked]>
Date: Mon, 27 Oct 2008 18:07:36 +0100

`quit-window' looks fishy in a number of regards: The `delete-frame'
stuff needs other_visible_frames to work correctly but this is not
available in Elisp.  I plan to commit somthing like the version below.
Could people please test whether it breaks their favorite use of this?

martin

(defun quit-window (&optional kill window)
   "Bury or kill (with KILL non-nil) the buffer displayed in WINDOW.
KILL defaults to nil, WINDOW to the selected window.  If WINDOW
is dedicated or a minibuffer window, delete it and, if it's the
only window on its frame, delete its frame as well provided there
are other frames left.  Otherwise, display some other buffer in
the window."
   (interactive)
   (let* ((window (or window (selected-window)))
	 (buffer (window-buffer window)))
     (if (or (window-minibuffer-p window) (window-dedicated-p window))
	(if (eq window (frame-root-window (window-frame window)))
	    ;; If this is the only window on its frame, try to delete the
	    ;; frame (`delete-windows-on' knows how to do that).
	    (delete-windows-on buffer (selected-frame))
	  ;; Other windows are left, delete this window.  But don't
	  ;; throw an error if that fails for some reason.
	  (condition-case nil
	      (delete-window window)
	    (error nil)))
       ;; The window is neither dedicated nor a minibuffer window,
       ;; display another buffer in it.
       (with-selected-window window
	(switch-to-buffer (other-buffer))))

     ;; Deal with the buffer.
     (if kill
	(kill-buffer buffer)
       (bury-buffer buffer))))