1

I'll get terminology wrong here, so be gentle with that (only).

cd ~/src/
./emacs *
C-x 2

So I've got two windows here, one above the other, and a bunch of files in my buffer list (more than 2). When I C-x k to kill the buffer that I'm in, of course its window then shows another buffer from my open list.

From 1997 to 2014, or so, Emacs has worked hard to avoid the buffer I also have open in another pane (which is usually awesome). Recently though, when I use C-x k Emacs just loads whatever the next-most-recently-used buffer was into the selected window .. and that's usually the buffer I already have open in the other pane. So then it looks like:

--top-bordery-border--
file #1 stuff
-UUU:%--F1- [mode] ---
file #1 stuff
-UUU:%--F1- [mode] ---

... which can be called Silly, most times.

Has anyone who can understand my bad description, who's seen that behaviour, know how to get the older behaviour back?

Stefan
  • 26,154
  • 3
  • 46
  • 84
user2066657
  • 138
  • 6
  • In my window user-customizations, I have a note that `window.c` defines `replace-buffer-in-windows`, which function is defined in `window.el`. It may be as simple as you opening an older version of Emacs that you liked and type `M-x find-function RET replace-buffer-in-windows RET` and then copy that function over to your current `.emacs`/`init.el` file. You will not need to `require` any libraries for the new function with the same name to supercede the older function. Although I have not specifically tried what I am suggesting, I do use a modified version of that function in my own setup. – lawlist Mar 22 '18 at 00:38
  • See also this related (or duplicate?) thread entitled "**replace-buffer-in-windows issues in switching from emacs 24.5 to emacs 25.2**": https://emacs.stackexchange.com/questions/36881/replace-buffer-in-windows-issues-in-switching-from-emacs-24-5-to-emacs-25-2 – lawlist Mar 22 '18 at 01:07
  • 36881 is exactly similar behaviour -- the solution looks very promising. (repost your comment as an answer so I can flag it right?) Thanks! – user2066657 Mar 22 '18 at 08:01
  • My solution would be different than the one by @Tobias; i.e., I would diff the `replace-buffer-in-windows` from a previous Emacs version with that of the current version and go from there .... This comment should draw the attention of the above-mentioned user, and he is certainly free to post his own answer here and when you accept it, the related/duplicate question can be marked as such and closed. If this will end up being the master question on that issue, you or someone else may deem it appropriate to have a better title so Google and forum searchers can find this thread easily. – lawlist Mar 22 '18 at 16:27

1 Answers1

2

I had the same issue with the newer Emacsen. I finally found a solution that seems to work. There is a configuration setting called switch-to-visible-buffer which default to t. Set it to nil via M-x customize-variable or with a (set switch-visible-buffer nil) in your $HOME/.emacs file.

Here's the help for switch-to-visible-buffer:

switch-to-visible-buffer is a variable defined in ‘window.el’.
Its value is nil
Original value was t

Documentation:
If non-nil, allow switching to an already visible buffer.
If this variable is non-nil, ‘switch-to-prev-buffer’ and
‘switch-to-next-buffer’ may switch to an already visible buffer.
If this variable is nil, ‘switch-to-prev-buffer’ and
‘switch-to-next-buffer’ always try to avoid switching to a buffer
that is already visible in another window on the same frame.

You can customize this variable.

This variable was introduced, or its default value was changed, in
version 24.1 of Emacs.
Brad Howes
  • 36
  • 4