Subject: Re: bug#13167: 24.3.50; C-x right C-x left interferes with buffer order

From: martin rudalics <[email-masked]>
Date: Fri, 14 Dec 2012 11:25:19 +0100

>> Why do you never quit the *Messages* buffer in your scenario?
 >
 > I can't quit the *Messages* buffer.  Typing `q' inserts the character
 > `q' to the *Messages* buffer.  But it's good that *Messages* is writable.
 > The same problem can occur with any other writable buffer.

You can always do M-x quit-window.  Isn't there some C-x binding we
could use for this?

 >> The semantics of C-x left and C-x right is that you want (or
 >> at least don't mind) to switch back to the old buffer.
 >
 > Typing `C-x left' in the *Messages* buffer in the aforementioned scenario adds
 > the *Messages* buffer to both (window-prev-buffers) and to (window-next-buffers).
 > This looks doubtful.  Is this intentional?

Yes.  When in `switch-to-next-buffer'

       (dolist (buffer next-buffers)
	(when (and (or (buffer-live-p buffer)
		       (not (setq killed-buffers
				  (cons buffer killed-buffers))))
		   (not (eq buffer old-buffer))
                    (or (null pred) (funcall pred buffer))
		   (setq entry (assq buffer (window-prev-buffers window))))
	  (setq new-buffer buffer)
	  (set-window-buffer-start-and-point
	   window new-buffer (nth 1 entry) (nth 2 entry))
	  (throw 'found t)))

this loop finds a buffer to switch to, it retrieves the start and point
positions from the buffer's association in the window's _previous_
buffers.  I didn't want to maintain the same markers twice.

 > I thought that when a buffer is displayed for the first time
 > (e.g. with `C-h C-n', or `v' in Dired mode), it sets up `quit-window',
 > so `q' will be able to return to the buffer that initiated its display.

The dichotomy striking here is rooted in the history of `quit-window'
which was used (via "q") for getting rid of temporary, typically
read-only buffers, but also for generally getting rid of a window's
contents.

 > I didn't expect that `C-x right C-x left' affects `quit-window'.

They both affect each other.  If there's no explicit `quit-restore'
parameter, `quit-window' uses whatever `window-prev-buffers' provides.
And quitting a window should make its buffer move to the far ends of its
previous and next buffers.

martin