Emacs buffer shown after closing the buffer

How can I change the way emacs chooses which buffer to display after closing the buffer?

When I have several columns showing the same buffer, and then open another file in one of the buffers and then close the newly opened buffer, it will not switch to the previous buffer, but to another buffer.

I will try to explain with an example:

  • Start with the new emacs with * scratch *
  • Cx 2 (divided into two columns)
  • Cx Cf 1 (find file 1)
  • Cx o (switch to another frame)
  • Cx b 1 (find file 1)
  • Cx Cf 2 (find file 2)
  • Cx k (kill buffer)

Now it switches to scratch, but I would like it to display 1 again in both windows, is it possible to make emacs behave this way?

+7
source share
3 answers

This may not be a direct answer to your question, but it can help.

Emacs manages its list of buffers, including choosing which buffer is displayed when you kill it (via kill-buffer ). I did not watch how this is done, but the documentation is "there . " Many people have created custom buffer-stack control magic to change the way emacs does things, maybe some of them are based on Bayesian analysis or something else. You can imagine the possibilities.

I have never looked at how emacs manages its buffers. Instead, I just bind the other-window and switch-to-buffer to simple keystrokes (Cx o, Cx b), and I use them very well.

you can create a simple function for what you want: it should destroy all other windows, and then split the window so that the current buffer is displayed in both. Fortunately, emacs has functions that do just that.

 (defun cheeso-show-buffer-two-windows () "Close all other windows; then split, and show the current buffer in both windows." (interactive) (delete-other-windows) (split-window-vertically)) 

Bind this to a keystroke and badda-bing, you're there. This is a vertical split - windows are displayed in a vertical stack. If you want to divide it horizontally (windows side by side), then replace ... well, you know.

+3
source

It also doesn't help much directly, but Winner mode can help you get what you want to get.

0
source

Do you use tab mode? I had the same problem and there was a time sheet for me. Tabbar adds the tabbar-buffer-kill-buffer-hook function to kill-buffer-hook . You can remove it with (remove-hook 'kill-buffer-hook 'tabbar-buffer-kill-buffer-hook) .

If you are not using tabs, try Mx describe-variable kill-buffer-hook . One of the functions on this list should be responsible for the mess with your buffers.

0
source

All Articles