unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#1259: quit-window: does it quit the wrong buffer?
@ 2008-10-27  1:19 ` David Reitter
  2008-10-27 10:31   ` martin rudalics
  2008-10-30 15:50   ` bug#1259: marked as done (quit-window: does it quit the wrong buffer?) Emacs bug Tracking System
  0 siblings, 2 replies; 7+ messages in thread
From: David Reitter @ 2008-10-27  1:19 UTC (permalink / raw)
  To: emacs-pretest-bug

I'm wondering if there is a discrepancy between the doc string of quit- 
window and its implementation:  The function is supposed to quit the  
current buffer, but what it seems to do is to quit the buffer in the  
selected window.


(defun quit-window (&optional kill window)
   "Quit the current buffer.  Bury it, and maybe delete the selected  
frame.
\(The frame is deleted if it contains a dedicated window for the  
buffer.)
With a prefix argument, kill the buffer instead.

Noninteractively, if KILL is non-nil, then kill the current buffer,
otherwise bury it.

If WINDOW is non-nil, it specifies a window; we delete that window,
and the buffer that is killed or buried is the one in that window."
   (interactive "P")
   (let ((buffer (window-buffer window))
	(frame (window-frame (or window (selected-window))))






^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#1259: quit-window: does it quit the wrong buffer?
  2008-10-27  1:19 ` bug#1259: quit-window: does it quit the wrong buffer? David Reitter
@ 2008-10-27 10:31   ` martin rudalics
  2008-10-27 15:01     ` David Reitter
  2008-10-30 15:50   ` bug#1259: marked as done (quit-window: does it quit the wrong buffer?) Emacs bug Tracking System
  1 sibling, 1 reply; 7+ messages in thread
From: martin rudalics @ 2008-10-27 10:31 UTC (permalink / raw)
  To: David Reitter; +Cc: 1259

 > I'm wondering if there is a discrepancy between the doc string of
 > quit-window and its implementation:  The function is supposed to quit
 > the current buffer, but what it seems to do is to quit the buffer in the
 > selected window.

You're right.  The doc-string is wrong in other respects as well.  Does
the form below fit your needs?

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 and the only window on its frame, delete its frame
provided there are other frames left."
   (interactive)
   (let* ((window (or window (selected-window)))
	 (buffer (window-buffer window))
	 (frame (window-frame window))
	 window-solitary window-handled)
     (with-selected-window window
       (setq window-solitary (one-window-p t))
       (unless (or (window-minibuffer-p) (window-dedicated-p))
	(switch-to-buffer (other-buffer))))
     ;; Get rid of the frame, if it has just one dedicated window
     ;; and other visible frames exist.
     (when (and (or (window-minibuffer-p window)
		   (window-dedicated-p window))
	       window-solitary
	       (frame-visible-p frame))
       (unless (and (eq default-minibuffer-frame frame)
		   (= 1 (length (minibuffer-frame-list))))
	(delete-frame frame))
       (setq window-handled t))
     ;; Deal with the buffer.
     (if kill
	(kill-buffer buffer)
       (bury-buffer buffer))
     ;; Maybe get rid of the window.
     (when (and (not window-handled) (not window-solitary))
       (delete-window window))))







^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#1259: quit-window: does it quit the wrong buffer?
  2008-10-27 10:31   ` martin rudalics
@ 2008-10-27 15:01     ` David Reitter
  2008-10-27 17:07       ` martin rudalics
  0 siblings, 1 reply; 7+ messages in thread
From: David Reitter @ 2008-10-27 15:01 UTC (permalink / raw)
  To: martin rudalics; +Cc: 1259

[-- Attachment #1: Type: text/plain, Size: 471 bytes --]

On 27 Oct 2008, at 06:31, martin rudalics wrote:

> > I'm wondering if there is a discrepancy between the doc string of
> > quit-window and its implementation:  The function is supposed to  
> quit
> > the current buffer, but what it seems to do is to quit the buffer  
> in the
> > selected window.
>
> You're right.  The doc-string is wrong in other respects as well.   
> Does
> the form below fit your needs?

The doc string you sent seems appropriate to me, thanks. 

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2193 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#1259: quit-window: does it quit the wrong buffer?
  2008-10-27 15:01     ` David Reitter
@ 2008-10-27 17:07       ` martin rudalics
  2008-11-04 17:40         ` David Reitter
  0 siblings, 1 reply; 7+ messages in thread
From: martin rudalics @ 2008-10-27 17:07 UTC (permalink / raw)
  To: David Reitter; +Cc: 1259

`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))))







^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#1259: marked as done (quit-window: does it quit the wrong  buffer?)
  2008-10-27  1:19 ` bug#1259: quit-window: does it quit the wrong buffer? David Reitter
  2008-10-27 10:31   ` martin rudalics
@ 2008-10-30 15:50   ` Emacs bug Tracking System
  1 sibling, 0 replies; 7+ messages in thread
From: Emacs bug Tracking System @ 2008-10-30 15:50 UTC (permalink / raw)
  To: martin rudalics

[-- Attachment #1: Type: text/plain, Size: 853 bytes --]


Your message dated Thu, 30 Oct 2008 16:42:17 +0100
with message-id <4909D5D9.60300@gmx.at>
and subject line Re: bug#1259: quit-window: does it quit the wrong buffer?
has caused the Emacs bug report #1259,
regarding quit-window: does it quit the wrong buffer?
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact don@donarmstrong.com
immediately.)


-- 
1259: http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=1259
Emacs Bug Tracking System
Contact don@donarmstrong.com with problems

[-- Attachment #2: Type: message/rfc822, Size: 3976 bytes --]

From: David Reitter <david.reitter@gmail.com>
To: emacs-pretest-bug@gnu.org
Subject: quit-window: does it quit the wrong buffer?
Date: Sun, 26 Oct 2008 21:19:48 -0400
Message-ID: <E42FC1D6-A191-475C-88BD-F9FA2C50C78B@gmail.com>

I'm wondering if there is a discrepancy between the doc string of quit- 
window and its implementation:  The function is supposed to quit the  
current buffer, but what it seems to do is to quit the buffer in the  
selected window.


(defun quit-window (&optional kill window)
   "Quit the current buffer.  Bury it, and maybe delete the selected  
frame.
\(The frame is deleted if it contains a dedicated window for the  
buffer.)
With a prefix argument, kill the buffer instead.

Noninteractively, if KILL is non-nil, then kill the current buffer,
otherwise bury it.

If WINDOW is non-nil, it specifies a window; we delete that window,
and the buffer that is killed or buried is the one in that window."
   (interactive "P")
   (let ((buffer (window-buffer window))
	(frame (window-frame (or window (selected-window))))



[-- Attachment #3: Type: message/rfc822, Size: 1649 bytes --]

From: martin rudalics <rudalics@gmx.at>
To: 1259-done@emacsbugs.donarmstrong.com
Cc: David Reitter <david.reitter@gmail.com>
Subject: Re: bug#1259: quit-window: does it quit the wrong buffer?
Date: Thu, 30 Oct 2008 16:42:17 +0100
Message-ID: <4909D5D9.60300@gmx.at>

Fixed as

2008-10-30  Martin Rudalics  <rudalics@gmx.at>

	* window.el (quit-window): Simplify code.  Say in doc-string
	that it operates on the selected window's buffer.  (Bug#1259)

Thanks, martin


^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#1259: quit-window: does it quit the wrong buffer?
  2008-10-27 17:07       ` martin rudalics
@ 2008-11-04 17:40         ` David Reitter
  2008-11-04 18:15           ` martin rudalics
  0 siblings, 1 reply; 7+ messages in thread
From: David Reitter @ 2008-11-04 17:40 UTC (permalink / raw)
  To: martin rudalics; +Cc: 1259

[-- Attachment #1: Type: text/plain, Size: 1941 bytes --]

Sorry for the delay.

On 27 Oct 2008, at 13:07, martin rudalics wrote:

> `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?


Is there a reason why you're not calling delete-window-on in all cases?
Why the condition-case only for delete-window?

Also, why the explicit switch-to-buffer?
Should quit-window switch to the buffer that would be displayed if the  
current buffer was killed or just buried?

- David

>
>
> (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))))
>


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2193 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#1259: quit-window: does it quit the wrong buffer?
  2008-11-04 17:40         ` David Reitter
@ 2008-11-04 18:15           ` martin rudalics
  0 siblings, 0 replies; 7+ messages in thread
From: martin rudalics @ 2008-11-04 18:15 UTC (permalink / raw)
  To: David Reitter; +Cc: 1259

 > Is there a reason why you're not calling delete-window-on in all cases?

Just for the case that I have two windows showing the same buffer and
invoke `quit-window' on one of them.  In this case I want to leave the
other window alone.  (BTW, using `delete-windows-on' for a frame showing
_one_ window is a kludge - but `delete-windows-on' is the only function
I found that handles some corner cases in this area correctly.)

 > Why the condition-case only for delete-window?

I don't think it's needed.  But delete_window has a strange loop I never
understood completely which can err with "Cannot delete window" and I
wanted to avoid that.

 > Also, why the explicit switch-to-buffer?
 > Should quit-window switch to the buffer that would be displayed if the
 > current buffer was killed or just buried?

That was already in the old version of `quit-window'.  Note that when
WINDOW is not the selected window, `bury-buffer' leaves the buffer
displayed in WINDOW.  `quit-window' must remove the buffer from WINDOW
even if WINDOW is not selected.

In any case, don't expect too much from `quit-window'.  The underlying
logic is too weak to make it more useful.  What we really need is a
buffer-local variable say `quit-windows-on' which, when set, triggers
some special code in `set-window-buffer' and `display-buffer'.  The
former would simply record in a window-local variable `how-to-quit' the
buffer formerly displayed in the window and `quit-window' could switch
to that buffer, provided its still live.

`display-buffer' would do the same but in addition, when it splits a
window to display the buffer, set `how-to-quit' to t so `quit-window'
could eventually delete that window.  A similar solution would have
`quit-window' delete a stand-alone frame popped up by `display-buffer'.

Most of this has been implemented in Lisp in some form or the other but
that's not sufficient.  `set-window-buffer' must act on this.

martin







^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-11-04 18:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <4909D5D9.60300@gmx.at>
2008-10-27  1:19 ` bug#1259: quit-window: does it quit the wrong buffer? David Reitter
2008-10-27 10:31   ` martin rudalics
2008-10-27 15:01     ` David Reitter
2008-10-27 17:07       ` martin rudalics
2008-11-04 17:40         ` David Reitter
2008-11-04 18:15           ` martin rudalics
2008-10-30 15:50   ` bug#1259: marked as done (quit-window: does it quit the wrong buffer?) Emacs bug Tracking System

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).