1

ISTR that quit-window and bury-buffer made sure that the replacement/newly displayed buffer is not shown in any other window (at least that was my intention when I wrote quit-window many years ago).

Right now I see that C-x b (switch-to-buffer) offers a good candidate (IOW, other-buffer returns a buffer that is not currently shown), but both quit-window and bury-buffer replace the current buffer with one that is already displayed in another window in the current frame.

Is there a way to restore the original behavior of never displaying an already visible buffer?

Is this a (known) bug?

(I have no easy access to email, so, alas, I cannot easily submit an emacs bug report).

PS. GNU Emacs 29.1 (build 2, x86_64-w64-mingw32) of 2023-08-02

Postmortem: it turned out that I have been setting switch-to-prev-buffer-skip to t since forever, but only at home (where I have ~30 years worth of settings under git), while at work I was not able to bring all those settings over, and I now I have to recover them one by one.

1 Answer 1

2

Try:

(setq switch-to-prev-buffer-skip t)

Docstring excerpt of note:

Since ‘switch-to-prev-buffer’ is called by ‘bury-buffer’, ‘replace-buffer-in-windows’ and ‘quit-restore-window’ among others, customizing this option may also affect the behavior of Emacs when a window is quit or a buffer gets buried or killed.

In full (from 29.2):

switch-to-prev-buffer-skip is a variable defined in ‘window.el’.

Its value is nil

Buffers ‘switch-to-prev-buffer’ should skip.
If this variable is nil, ‘switch-to-prev-buffer’ may switch to
any buffer, including those already shown in other windows.

If this variable is non-nil, ‘switch-to-prev-buffer’ will refrain
from switching to certain buffers according to the value of this
variable:

- ‘this’ means do not switch to a buffer shown on the frame that
  hosts the window ‘switch-to-prev-buffer’ is acting upon.

- ‘visible’ means do not switch to a buffer shown on any visible
  frame.

- 0 (the number zero) means do not switch to a buffer shown on
  any visible or iconified frame.

- t means do not switch to a buffer shown on any live frame.

If this option specifies a function, that function is called with
three arguments - the WINDOW argument of ‘switch-to-prev-buffer’,
a buffer ‘switch-to-prev-buffer’ intends to switch to and the
BURY-OR-KILL argument of ‘switch-to-prev-buffer’.  If that
function returns non-nil, ‘switch-to-prev-buffer’ will not switch
to that buffer.

Since ‘switch-to-prev-buffer’ is called by ‘bury-buffer’,
‘replace-buffer-in-windows’ and ‘quit-restore-window’ among
others, customizing this option may also affect the behavior of
Emacs when a window is quit or a buffer gets buried or killed.

The value of this option is consulted by ‘switch-to-next-buffer’
as well.  In that case, if this option specifies a function, it
will be called with the third argument nil.

Under certain circumstances ‘switch-to-prev-buffer’ may ignore
this option, for example, when there is only one buffer left.

Also see ‘switch-to-prev-buffer-skip-regexp’.

  This variable was introduced, or its default value was changed, in
  version 27.1 of Emacs.
  You can customize this variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.